dfinity / motoko

Simple high-level language for writing Internet Computer canisters
Apache License 2.0
515 stars 97 forks source link

Bug: Type checker allows missing record fields in record literals #2331

Closed matthewhammer closed 3 years ago

matthewhammer commented 3 years ago
Stderr:
Ill-typed intermediate code after Desugaring (use -v to see dumped IR):
(unknown location): IR type error [M0000], subtype violation:
  {caption : Text; chunk : Nat; createdAt : Text; name : Text; tags : [Text]; userId : Text}
  {caption : Text; chunkCount : Nat; createdAt : Timestamp; name : Text; tags : [Text]; userId : UserId}

Raised at Ir_def__Check_ir.error.(fun) in file "ir_def/check_ir.ml", line 89, characters 30-92
Called from Ir_def__Check_ir.check_exp.(<:) in file "ir_def/check_ir.ml" (inlined), line 361, characters 19-45
Called from Ir_def__Check_ir.check_exp in file "ir_def/check_ir.ml", line 734, characters 4-30
Called from Ir_def__Check_ir.check_exp in file "ir_def/check_ir.ml", line 611, characters 4-23
Called from Stdlib__list.iter in file "list.ml", line 110, characters 12-15
Called from Ir_def__Check_ir.check_exp in file "ir_def/check_ir.ml", line 379, characters 4-32
Called from Ir_def__Check_ir.check_exp in file "ir_def/check_ir.ml", line 621, characters 4-22
Called from Ir_def__Check_ir.check_dec in file "ir_def/check_ir.ml", line 989, characters 4-21

Reproducing it

I don't have a minimal example yet, but I have a way to reproduce it and avoid it.

This tiny commit resolved the program type error and avoided this bug

nomeata commented 3 years ago

That’s odd: As if the type checker was incomplete. Minimal example:

ignore ({foo = 0} : { bar : Nat });
rossberg commented 3 years ago

That example is correctly rejected on my local build (which is a few weeks behind TOT). Looks like a bug with the new record typing, @crusso?

nomeata commented 3 years ago

Fix in https://github.com/dfinity/motoko/pull/2332