motoko icon indicating copy to clipboard operation
motoko copied to clipboard

feat: relaxes grammar to allow un-parenthesized unary operator patterns

Open christoph-dfinity opened this issue 1 month ago • 2 comments

As there's no ambiguity arising from this, I think it's consistent and more convenient to group unary operator patterns (like case -1) with the other literals.

christoph-dfinity avatar Oct 27 '25 08:10 christoph-dfinity

Comparing from 82171b1cde8d9ac3b0fcbbfc0e656fb22bf810c0 to c6bc1e0de579ea9cff446a707ba15182735c4526: In terms of gas, no changes are observed in 5 tests. In terms of size, no changes are observed in 5 tests.

github-actions[bot] avatar Oct 27 '25 09:10 github-actions[bot]

I guess that's ok, but I think it might break the symmetry with expressions:


crusso@crusso-Virtual-Machine:~/motoko/src$ rlwrap moc
Motoko compiler (source 0.16.3-40-g5e9da46fa)
> func id(x:Int):Int{x};
let id : (x : Int) -> Int = <func>
> id -1;
stdin:2.5-2.6: type error [M0050], literal of type
  Nat
does not have expected type
  (x : Int) -> Int
> id (-1);
-1 : Int
> -1;
-1 : Int

I must admit, I have a hard time understanding this error:

> id -1;
stdin:2.5-2.6: type error [M0050], literal of type
  Nat
does not have expected type
  (x : Int) -> Int

crusso avatar Oct 27 '25 10:10 crusso