dfinity / motoko

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

Bug: Invalid_argument Type.lookup_val_field #2317

Closed matthewhammer closed 3 years ago

matthewhammer commented 3 years ago
Fatal error: exception (Invalid_argument Type.lookup_val_field)
Raised at Mo_types__Type.invalid in file "mo_types/type.ml", line 365, characters 16-54
Called from Codegen__Compile.Object.is_mut_field in file "codegen/compile.ml", line 2635, characters 16-48

Some details here: https://github.com/dfinity/cancan/pull/70#issuecomment-774483364

nomeata commented 3 years ago

Here is a small reproducer:

actor {
  public func baz(b : Bool) : () {
      ignore({b = b} : {})
  };
}

It only happens if it is a shared function, so likely related to await/async translation.

I think the backend expects the exp.note.Note.typ of a NewObjE Object to be “tight”, and include every field (to find out whether it is mutable or not). But Check_ir doesn’t enforce it, and the async/await translation breaks this.

Possible fixes:

@crusso what do you think?

nomeata commented 3 years ago

Actually, there is an easier fix: Look at the type note on the field, not the object. Then not even subtyping can get into the way.

nomeata commented 3 years ago

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

nomeata commented 3 years ago

That branch has both fixes, one of them reverted. Claudio, do you have a hunch which one is preferable?

crusso commented 3 years ago

Taking a look