Stream: beginners

Topic: Reassign or redeclare a constant?


view this post on Zulip Daren (Feb 27 2026 at 19:51):

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, roc will 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.

view this post on Zulip Luke Boswell (Feb 27 2026 at 20:11):

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.

view this post on Zulip Norbert Hajagos (Feb 27 2026 at 20:11):

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.

view this post on Zulip Norbert Hajagos (Feb 27 2026 at 20:12):

Just as I hit send :)

view this post on Zulip Daren (Feb 27 2026 at 20:16):

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

view this post on Zulip Luke Boswell (Feb 27 2026 at 20:24):

The roc app.roc or roc build app.roc call I mean

view this post on Zulip Daren (Feb 27 2026 at 20:25):

Of course, yeah I didn't grok the CI part

view this post on Zulip Anton (Feb 28 2026 at 12:14):

I corrected the explanation in #9220

view this post on Zulip Hubert Małkowski (Mar 02 2026 at 15:50):

What's the rationale behind avoiding shadowing in roc?

view this post on Zulip Anton (Mar 02 2026 at 16:03):

To avoid bugs/confusion and to simplify things.


Last updated: Mar 20 2026 at 12:28 UTC