mini-tutorial-new-compiler.md states:
Constants can't be reassigned or shadowed, so if you try to do
name =again in the same scope,rocwill give a compile-time error.
But if I do this:
main! = |_args| {
Stdout.line!("What's your name?")
name = Stdin.line!()
Stdout.line!("Hello, ${name}!")
name = Stdin.line!()
Stdout.line!("Hello, ${name}!")
Ok({})
}
If I run roc I get a warning but it then runs OK:
❯ roc
-- DUPLICATE DEFINITION --------------------------
The name name is being redeclared in this scope.
The redeclaration is here:
┌─ main.roc:10:5
│
10 │ name = Stdin.line!()
│ ^^^^
But name was already defined here:
┌─ main.roc:8:5
│
8 │ name = Stdin.line!()
│ ^^^^
Found 0 error(s) and 1 warning(s) for main.roc.
What's your name?
Bill
Hello, Bill!
Daren
Hello, Daren!
If I compile using roc build .\main.roc and run main.exe it also runs:
❯ …\Projects\Roc\test ❯ .\main
What's your name?
Bill
Hello, Bill!
Daren
Hello, Daren!
I feel that I'm missing something fundamental, because this doesn't match my expectations.
Im guessing the tutorial is a little too conservative here.
The design philosophy is "inform dont block" -- we built support for canonicalizing shadowed identifiers so we can give a helpful error message.
I'm not sure about the difference between an Error and a Warning...
You should find that roc exited with a non-zero code -- which indicates there is an error and is intended to prevent this from slipping through CI.
I think this is the status, because the guiding principle is not to block the user from running their code if the error isn't something where we cannot determine what would be the right thing to do. The expectation is that people won't ignore warnings.
Just as I hit send :)
Luke Boswell said:
You should find that roc exited with a non-zero code -- which indicates there is an error and is intended to prevent this from slipping through CI.
This doesn't appear to be the case: https://i.postimg.cc/157gSz72/image.png
The roc app.roc or roc build app.roc call I mean
Of course, yeah I didn't grok the CI part
I corrected the explanation in #9220
What's the rationale behind avoiding shadowing in roc?
To avoid bugs/confusion and to simplify things.
Last updated: Mar 20 2026 at 12:28 UTC