HaxeFoundation / HaxeFoundation/haxe
write-mode @:op(a.b) macro
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
I'm not sure if this is a bug or I just don't know how to use this.
I've noticed new feature in change log and decided to test it.
Non-macro code works fine. Both with `@:resolve` and `@:op(a.b)`.
But I can't find a way to make macro work. How should this work?
```haxe
abstract MacroMap(Map) from Map {
@:op(a.b)
private macro static function getField(ethis:haxe.macro.Expr, name:String) {
return macro (cast $ethis: Map).get($v{name});
}
@:op(a.b)
public macro static function setField(ethis:haxe.macro.Expr, name:String, evalue: haxe.macro.Expr) {
return macro (cast $ethis: Map).set($v{name}, $evalue);
}
}
class Test {
public static function main() {
var t: MacroMap = ["hello"=>"world"];
trace(t.hello);
MacroMap.setField(t, "world", "hello"); // this compiles fine
t.world = "hello"; // String should be haxe.macro.Expr
trace(t.world);
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.