roc-lang / roc

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

REPL on roc-lang.org panics on attempt to redefine/shadow a variable #6315

Open danieltuveson opened 8 months ago

danieltuveson commented 8 months ago

If I type in x = 1 into the REPL at roc-lang.org and then try to redefine it as x = 2, the interpreter crashes with the following error:

panicked at 'not yet implemented', crates/compiler/mono/src/ir.rs:2744:23

Stack:

Error
    at imports.wbg.__wbg_new_abda76e883ba8a5f (https://www.roc-lang.org/repl/roc_repl_wasm.js:314:21)
    at console_error_panic_hook::hook::h1099fea33a901b03 (https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[1152]:0x349f59)
    at std::panicking::rust_panic_with_hook::h6df5db7ad9f65dc8 (https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[2624]:0x3c2fc0)
    at std::panicking::begin_panic_handler::{{closure}}::h0d169fa297411d6d (https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[3095]:0x3d8448)
    at std::sys_common::backtrace::__rust_end_short_backtrace::h7fe51fb4d3ba6060 (https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[5081]:0x3fe7c9)
    at rust_begin_unwind (https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[4337]:0x3f7efd)
    at core::panicking::panic_fmt::h2d3c5586175098d9 (https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[4402]:0x3f8f17)
    at core::panicking::panic::h04b2835ef9b41d19 (https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[4144]:0x3f4aff)
    at roc_mono::ir::from_can_let::hce04e39fa779fa20 (https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[122]:0x1a7969)
    at roc_mono::ir::from_can::h9e71197c2379e43e (https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[161]:0x1e04df)
Anton-4 commented 8 months ago

Thanks for reporting this Daniel! Just so you know, Roc does not allow redefinition. We should of course print a nice error message when the user tries it!

danieltuveson commented 8 months ago

Yep, I assumed as much! Sometimes languages that don't allow redefinition do allow redefinition within the REPL (Haskell and GHCI, for instance), that way you don't need to restart the REPL to change the definition of a function, for example. But mainly I wanted to note that it panics instead of giving a compiler error.

gvwilson commented 6 months ago

Just hit the same issue—can a better error message for this please be prioritized? People coming to Roc from imperative languages are going to hit this almost immediately, and a more informative error message would help first contact.