haxe icon indicating copy to clipboard operation
haxe copied to clipboard

Abstract Macro @:op(A.B) overloading weird

Open filt3rek opened this issue 3 years ago • 0 comments

Hej,

Sorry I don't know if it's a bug or maybe I don't understand things. I tried to do a minimalistic example to illustrate what's going on : https://try.haxe.org/#B33dD5ED

import haxe.macro.Expr;
import haxe.macro.Context;

using haxe.macro.Tools;

abstract Foo(Dynamic) from Dynamic to Dynamic {
	@:op(A.B) function get(prop:String) {
		return Reflect.field(this, prop);
	}

	@:op(A.B) macro function set(obj:Expr, prop:Expr, val:Expr) {
		trace(Context.getTypedExpr(Context.typeExpr(obj)).toString(), prop.toString(), Context.getTypedExpr(Context.typeExpr(val)).toString());
		return macro $val;
	}
}

class Test {
	static function main() {
		var foo:Foo = {
			n: 5
		};
		foo.n = 4;	// compiler trace => foo,"n",4 => So "obj" = "foo" OK
		foo.n += 4;	// compiler trace => Test.Foo_Impl_.get(foo, "n") + 4,"n",Test.Foo_Impl_.get(foo, "n") + 4
				// So "obj" = "Test.Foo_Impl_.get(foo, "n") + 4" ???
	}
}

Is it normal please ?

filt3rek avatar Sep 07 '22 17:09 filt3rek