roc-lang / roc

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

Crash inserting into empty Dict #6084

Open MFAshby opened 9 months ago

MFAshby commented 9 months ago

Trying to create a dictionary with a single entry using the following line in Roc:

foo = Dict.insert Dict.empty "foo" 123i64

Expected to get a Dict with a single entry key: "foo", value: (I64 123)

Actually got this crash using the online repl:

Enter an expression to evaluate, or a definition (like x = 1) to use later.
» foo = Dict.insert Dict.empty "foo" 123i64
Roc failed with message: "Erroneous: specialize_symbol"
panicked at 'capacity overflow', /home/big-ci-user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bumpalo-3.14.0/src/collections/raw_vec.rs:691:5

Stack:

__wbg_get_imports/imports.wbg.__wbg_new_abda76e883ba8a5f@https://www.roc-lang.org/repl/roc_repl_wasm.js:314:21
console_error_panic_hook::hook::h1099fea33a901b03@https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[1150]:0x34126a
std::panicking::rust_panic_with_hook::h6df5db7ad9f65dc8@https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[2624]:0x3ba508
std::panicking::begin_panic_handler::{{closure}}::h0d169fa297411d6d@https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[3090]:0x3cf602
std::sys_common::backtrace::__rust_end_short_backtrace::h7fe51fb4d3ba6060@https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[5073]:0x3f58b1
rust_begin_unwind@https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[4331]:0x3ef036
core::panicking::panic_fmt::h2d3c5586175098d9@https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[4397]:0x3f0090
bumpalo::collections::raw_vec::capacity_overflow::h4a39e1eb1611f5dd@https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[4402]:0x3f01bb
bumpalo::collections::raw_vec::RawVec::allocate_in::h4cdd8ac0d225420b@https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[2268]:0x3a7685
roc_repl_eval::eval::list_to_ast::ha5f1edbb8e68d444@https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[811]:0x30442f
roc_repl_eval::eval::addr_to_ast::he0fb25f3f0a6011c@https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[135]:0x1b8f8d
roc_repl_eval::eval::struct_to_ast::h8af1f7cd1bcabde9@https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[112]:0x191864
roc_repl_wasm::repl::eval_wasm::{{closure}}::had0cb47aea0fdeb2@https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[35]:0x966cf
wasm_bindgen_futures::future_to_promise::{{closure}}::{{closure}}::ha8d95284e390528f@https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[397]:0x281961
wasm_bindgen_futures::queue::Queue::new::{{closure}}::h53e50a293a7d9b98@https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[1544]:0x370b51
wasm_bindgen::convert::closures::invoke1_mut::h7dcdcbc0922500bc@https://www.roc-lang.org/repl/roc_repl_wasm_bg.wasm:wasm-function[4753]:0x3f42c0
__wbg_adapter_12@https://www.roc-lang.org/repl/roc_repl_wasm.js:205:10
real@https://www.roc-lang.org/repl/roc_repl_wasm.js:190:20

And the same error message running the repl on my machine (linux GNU aarch64)

Note I don't think the problem is the value type, I get the same error with this line:

lukewilliamboswell commented 9 months ago

Roc should return a nice error here.

Note that if you use foo = Dict.insert (Dict.empty {}) "foo" 123i64 it works correctly. The empty fn needs to be called to create a Dict.

MFAshby commented 9 months ago

Awesome thanks, yeah I didn't spot I had missed actually calling the function!

Roc should return a nice error here.

Agreed, an error message would have helped me spot that myself.