roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.46k stars 313 forks source link

Variable can be used before it is defined #6897

Closed dykstrom closed 1 month ago

dykstrom commented 4 months ago

This example program builds and runs fine, even though variable "bar" is undefined when it is used.

I am using roc nightly pre-release, built from commit 3abc276 on Fri Jul 5 09:11:06 UTC 2024. Operating system: macOS.

app [main] {
    cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.11.0/SY4WWMhWQ9NvQgvIthcv15AUeA7rAIJHAHgiaSHGhdY.tar.br",
}

import cli.Stdout

foo = \value -> value

main =
    x = foo bar
    bar = 17
    Stdout.line! "Value: $(Num.toStr x)"
bhansconnect commented 1 month ago

This is actually expected in current roc. Since there are only immutable values and not actual variables, this is totally. That said, we do have plans to make it a warning in the future.

dykstrom commented 1 month ago

Well, if it is by design, then we can close this issue. But it was a bit surprising to me, so I would certainly appreciate a warning.