Motoko compiler bug when using inspect system function with endpoint receiving tuple arguments

Hello community! Today I found that I cannot compile my actor anymore after migrating my shared function to receive tuple of Nat-s instead of one single Nat. I narrowed down the issue and found that inspect function is to blame, it does not work when it’s declared

DFX version: 0.12.1 and 0.12.2-beta.0
OS: MacOS Ventura 13.1

The error:

Ill-typed intermediate code after Desugaring (use -v to see dumped IR):
(unknown location): IR type error [M0000], bad case
Raised at Ir_def__Check_ir.error.(fun) in file "ir_def/check_ir.ml", line 95, characters 30-92
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 712, characters 4-30
Called from Ir_def__Check_ir.check_dec in file "ir_def/check_ir.ml", line 1084, characters 4-21
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 695, characters 4-22
Called from Ir_def__Check_ir.check_dec in file "ir_def/check_ir.ml", line 1084, characters 4-21
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 695, characters 4-22
Called from Ir_def__Check_ir.check_comp_unit in file "ir_def/check_ir.ml", line 1150, characters 4-27
Called from Ir_def__Check_ir.check_prog in file "ir_def/check_ir.ml", line 1163, characters 6-28

Minimal reproducing example:

actor class TestAPI() {
  public func endpoint(x: (Nat,Nat)) : async () {};
  system func inspect({}) : Bool = true;
};

Thanks for help and advises in advance!

1 Like

Reproduced the error with moc 0.7.6.

However, inside embed.smartcontracts.org the same code works.

Thanks for the small repro! I will take a look ASAP.

That’s probably because embed just uses the interpreter, so the inspect message won’t even be executed (and this is a bug in the intermediate representation used by compiled, not interpreted, code).

Created an issue for tracking

For now, if this works for your application, you can rewrite as follows to avoid the bug.

actor class TestAPI() {
 // public func endpoint(x: (Nat,Nat)) : async () {};
  public func endpoint(x:Nat, y: Nat) : async () {};
  system func inspect({}) : Bool = true;
};

Not that the new endpoint, at the candid level, now takes a 1-tuple with 2 items, rather than a 1-tuple whose first item is a 2-tuple, so the semantics is different (but perhaps what you were aiming for in the first place).

Will still fix the bug of course, but perhaps this unblocks you until the fix is in.

1 Like

Thanks! I look forward to seeing this fixed

Fixed in bugfix: fixes #3732 (bug in compilation of inspect) by crusso · Pull Request #3733 · dfinity/motoko · GitHub
Next release must contain the fix.

1 Like

Moc 0.8.1 has been released and should fix this.

3 Likes