Unhelpful error message when subtracting numbers without spaces
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.
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?
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
- 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-xwould just fail and force them to write1 - x. Ideally, also1- xshould fail.-as unary operator. This is mostly personal taste. I have a dislike for prefix and postfix operators. I almost always writex = x + 1instead ofx++. I am also happy to write0 - xinstead ofx, like here:https://github.com/effekt-lang/effekt/blob/a4d5f589f1a59a8091f03410f75df735ae77cecc/libraries/common/effekt.effekt#L386-L387
def neg(n: Double): Double = 0.0 - nActually, I typically write
-1 * ...instead of0 - ...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).