effekt icon indicating copy to clipboard operation
effekt copied to clipboard

Unhelpful error message when subtracting numbers without spaces

Open Plixo2 opened this issue 1 month ago • 2 comments

The following code does not compile:

def main() = {
  println(1-2)
}

And produces the following error

Expected ) but got integer -2
  println(1-2)
           ^^

Although not tested, its probably because the - character gets included in the number literal, as indicated by the error.

I think this line could be removed and matchPattern() altered to handle the extra - Token for literal patterns.

This would also allow spacing between the sign bit and the digits.

Java also does not include the - for number literals

Plixo2 avatar Oct 27 '25 23:10 Plixo2

I just noticed, that Effekt does not support unary operators at all, so this fix will not work, and this might be a duplicate of #507. Whats the state of unary operators for Effekt?

Plixo2 avatar Oct 27 '25 23:10 Plixo2

Hi, thanks for the report!

The latest decision of the Effekt working group on these issues was the following from #507 by @b-studios:

Ok, here are two points to address

  1. spaces: a lot of Effekt code is written by students (in theses, etc.). Since we do not have a nice formatter, they end up using the most creative way to use whitespaces. I would be very happy if 1-x would just fail and force them to write 1 - x. Ideally, also 1- x should fail.
  2. - as unary operator. This is mostly personal taste. I have a dislike for prefix and postfix operators. I almost always write x = x + 1 instead of x++. I am also happy to write 0 - x instead of x, like here:

https://github.com/effekt-lang/effekt/blob/a4d5f589f1a59a8091f03410f75df735ae77cecc/libraries/common/effekt.effekt#L386-L387

 def neg(n: Double): Double = 
   0.0 - n 

Actually, I typically write -1 * ... instead of 0 - ...and I think it works pretty well in your example as well.

We can talk it over at the next meeting, but I mostly agree with the quoted text above; the only thing I'd like improve is the error message in this case (but I don't find it too important right now).

jiribenes avatar Oct 28 '25 09:10 jiribenes