[macro] position


I have that :

class Test {
  static function main() {
    go( Macro.getInt() );
  static function go( n : Int ){
		trace( n );

And then that :

//use this for macros or other classes
class Macro {
  public static macro function getInt(){
		return macro "Foo";

When I compile I get an error, ok, but how to do to get the position in the call go( Macro.getInt() ); and not in the macro :

Macro.hx:4: characters 16-21 : String should be Int
Macro.hx:4: characters 16-21 : ... For function argument 'n'
Test.hx:1: lines 1-9 : ... Defined in this class

Here is the example : Try Haxe !

Use @:pos(haxe.macro.Context.currentPos()) : Try Haxe !

1 Like

Thanks Rudy !

I’ve done that before but with mistake : Instead of return macro @:pos(haxe.macro.Context.currentPos()) "Foo"; I’ve written return @:pos(haxe.macro.Context.currentPos()) macro "Foo";
And since Compiler didn’t told me anything, I thought all was good so I’ve been surprised.

Thanks ! :wink: