Stream: beginners

Topic: when roc allows run


view this post on Zulip dank (Mar 16 2023 at 22:40):

app "hello"
    packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.2.1/wx1N6qhU3kKva-4YqsVJde3fho34NqiLD3m620zZ-OI.tar.br" }
    imports [pf.Stdout]
    provides [main] to pf


foo = \name ->
    "hello \(name)"


main =
    foo = foo "dank"
    Stdout.line foo

this obviously should not work, and the errors are pretty good

── DUPLICATE NAME ─────────────────────────────────────────────────── keke.roc ─

The foo name is first defined here:

8│  foo = \name ->
    ^^^

But then it's defined a second time here:

13│      foo = foo "dank"
         ^^^

Since these variables have the same name, it's easy to use the wrong
one by accident. Give one of them a new name.


── TYPE MISMATCH ──────────────────────────────────────────────────── keke.roc ─

This 1st argument to line has an unexpected type:

14│      Stdout.line foo
                     ^^^

This foo value is a:

    Str -> Str

But line needs its 1st argument to be:

    Str

but it will still allow you to compile and run into

thread 'main' panicked at 'Error in alias analysis: error in module ModName("UserApp"), function definition FuncName("mainForHost"), definition of value binding ValueId(4): could not find func in module ModName("UserApp") with name FuncName("\x00\x00\x00\x00\x12\x00\x00\x00z\x87\xceV\x11\xaaYs")', crates/compiler/gen_llvm/src/llvm/build.rs:4764:19

so question being, as i know a goal of roc is to allow running even with type mismatches, should stuff like this be allowed?
like where is the line where roc says "this is unsound, im not compiling this"

note this is an alias analysis panic, not really _just_ a type thing

view this post on Zulip Brendan Hansknecht (Mar 17 2023 at 05:34):

So I think the goal is essentially, if we can replace part of your program with a runtime panic and otherwise lower it correctly, we want to do it. So in this case, we would maybe change the second definition of foo to a runtime panic. Then you could test part of your program and ipnore this issue.

view this post on Zulip Brendan Hansknecht (Mar 17 2023 at 05:34):

That said, I am not really sure where the line should be drawn, If we really don't know, we may have to add a runtime panic in many places or just give up during compilation. Either way, the error should be made way better than the crash you got.

view this post on Zulip dank (Mar 17 2023 at 15:10):

Brendan Hansknecht said:

So I think the goal is essentially, if we can replace part of your program with a runtime panic and otherwise lower it correctly, we want to do it. So in this case, we would maybe change the second definition of foo to a runtime panic. Then you could test part of your program and ipnore this issue.

oh yeah panic replacement sounds good here, didn't consider that


Last updated: Jul 06 2025 at 12:14 UTC