haxe
haxe copied to clipboard
Operators are inconsistent with block expressions
Example:
final b = a + {final x = 10; x * x;}; // this is fine
final b = {final x = 10; x * x;} + a; // this is a compiler error: "characters 34-35 : Expected }"
final b = ({final x = 10; x * x;}) + a; // this on the other hand is fine too.
I discovered this by coming across a similar example to the one displayed in the example below, which is preventing ufront from compiling with haxe 4: https://github.com/ufront/ufront/issues/28
@:callable
abstract Function(Int->Int) to Int->Int from Int->Int {
@:op(a + b)
static function add(a:Function, b:Function):Function {
return (i) -> a(b(i));
}
}
class Test {
static function main() {
final f:Function = (a) -> a + 1;
final g = ((a) -> {a * a;}) + f; // no issue here
final h = (a) -> {a * a;} + f; // Test.hx:13: characters 30-31 : Expected }
trace(g(10));
trace(h(10));
}
}