Open bhansconnect opened 8 months ago
Error message:
── TYPE MISMATCH in examples/helloWorld.roc ────────────────────────────────────
This 1st argument to add has an unexpected type:
11│ y = add { a : 7 }
^^^^^^^^^
The argument is a record of type:
{ … }
But add needs its 1st argument to be:
{ b : Int Unsigned64, … }
Tip: Looks like the b field is missing.
────────────────────────────────────────────────────────────────────────────────
In some cases, omitting optional record fields can also cause a compiler panic. Example can be found here
Panic message example:
thread 'main' panicked at 'Error in alias analysis: error in module ModName("UserApp"), function definition FuncName("\x11\x00\x00\x00\x02\x00\x00\x00\xcbr?\x05\x92\xae\x19\x92"), definition of value binding ValueId(3): expected type '(((), (), ()),)', found type '((),)'', crates/compiler/gen_llvm/src/llvm/build.rs:5761:19
For people looking for a workaround: You can use:
Xml : {
declaration : [Some Str, None],
root : Str,
}
Instead of:
Xml : {
xmlDeclaration ? Str,
root : Str,
}
Simple repro, run
roc check
on this code:Some reason, we can use add both with/without the optional field as
add { a : 7, b: 8 }
andadd { a : 7 }
.