mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
Turn invalid record field types into runtime errors
By emitting a runtime error rather than panicking when we can't layout a record, we help programs like ``` main = get = \{a} -> a get {b: "hello world"} ``` execute as ``` Mismatch in compiler/unify/src/unify.rs Line 1071 Column 13 Trying to unify two flat types that are incompatible: EmptyRecord ~ { 'a' : Demanded(122), }<130> 🔨 Rebuilding host... ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── The 1st argument to get is not what I expect: 8│ get {b: "hello world"} ^^^^^^^^^^^^^^^^^^ This argument is a record of type: { b : Str } But get needs the 1st argument to be: { a : a }b Tip: Seems like a record field typo. Maybe a should be b? Tip: Can more type annotations be added? Type annotations always help me give more specific messages, and I think they could help a lot in this case ──────────────────────────────────────────────────────────────────────────────── '+fast-variable-shuffle' is not a recognized feature for this target (ignoring feature) '+fast-variable-shuffle' is not a recognized feature for this target (ignoring feature) Done! Application crashed with message Can't create record with improper layout Shutting down ``` rather than the hanging ``` Mismatch in compiler/unify/src/unify.rs Line 1071 Column 13 Trying to unify two flat types that are incompatible: EmptyRecord ~ { 'a' : Demanded(122), }<130> thread '<unnamed>' panicked at 'invalid layout from var: UnresolvedTypeVar(104)', compiler/mono/s rc/layout.rs:1510:52 ``` that was previously produced. Part of #2227
This commit is contained in:
parent
e728e319c6
commit
576f1293fd
7 changed files with 96 additions and 51 deletions
|
@ -764,7 +764,8 @@ fn type_to_variable<'a>(
|
|||
let temp_ext_var = type_to_variable(subs, rank, pools, arena, ext);
|
||||
|
||||
let (it, new_ext_var) =
|
||||
gather_fields_unsorted_iter(subs, RecordFields::empty(), temp_ext_var);
|
||||
gather_fields_unsorted_iter(subs, RecordFields::empty(), temp_ext_var)
|
||||
.expect("Something ended up weird in this record type");
|
||||
|
||||
let it = it
|
||||
.into_iter()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue