HaxeFoundation / HaxeFoundation/haxe

[macro] Cannot access static field "" from a class instance

Open
#9,334 1 comment 0 reactions 0 assignees View on GitHub
platform-macro priority-netherlands
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Create two files:

Test.hx
```haxe
class Test {
public static macro function test() { // if you remove "macro" from the function. All works fine.
return macro null;
}
public static function main() {
var e = new Example();
e.macroFn(); // here is the compile error
}
}
```
Example.hx
```haxe
import haxe.macro.Expr;

class Example {
public function new() {}
public macro function macroFn(tthis:Expr) {
return macro {};
}
}
```

You get the error:
```
src/Test.hx:9: characters 7-14 : Cannot access static field macroFn from a class instance
```

tested with haxe 4.0.5 and latest nightly build 4.1.0-rc.1+adc9ed1b2

Edit (just for info):

The same issue also applies if you try it with @:using

Example.hx
```haxe
@:using(ExampleUsing)
class Example {
public function new() {}
}
```

ExampleUsing.hx
```haxe
import haxe.macro.Expr;

class ExampleUsing {
public static macro function macroFn(tthis:ExprOf) {
return macro {};
}
}
```

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.