HaxeFoundation / HaxeFoundation/haxe

write-mode @:op(a.b) macro

Open
#7,605 0 comments 0 reactions 0 assignees View on GitHub
bug feature-abstracts
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.