Macro reification, object instanciation error

89 views
Skip to first unread message

Jimmy Delas

unread,
Mar 14, 2014, 10:40:11 AM3/14/14
to haxe...@googlegroups.com
Hello again,

Here is are two differents way to write the same macro

macro public static function initClass() : Expr
{
var clazz = "hello.Hello";
return macro new $clazz();
}

macro public static function initClass() : Expr
{
return macro new hello.Hello();
}

The package hello is never included. In the very first case. It does not compile saying "Can't find class hello.Hello" whereas in the second case everything is fine.

Do I have any workaround without adding the import manually ? Even if the second solution work, I can't use it, it was just to showcase the problem I encountered.

Regards,

Simon Krajewski

unread,
Mar 14, 2014, 11:57:38 AM3/14/14
to haxe...@googlegroups.com
Haxe 3.0 had a weird behavior for type path reification where it tried to reify a String into a type path. This lead to unexpected behavior where a class name like "hello.Hello" was used, which is not possible from real syntax because it would become { pack: ["hello"], name: "Hello" } there.

This has been fixed since then and `new` now expects a TypePath object.

Simon

Jimmy Delas

unread,
Mar 14, 2014, 1:25:51 PM3/14/14
to haxe...@googlegroups.com
So I've updated my Haxe version to 3.1.0 but I'm still experiencing some errors

src/MacroFunctions.hx:44: characters 15-27 : String should be haxe.macro.TypePath
src/MacroFunctions.hx:44: characters 15-27 : String should be { ?sub : Null<String>, ?params : Array<haxe.macro.TypeParam>, pack : Array<String>, name : String }
src/MacroFunctions.hx:44: characters 15-27 : String has no field name
src/MacroFunctions.hx:44: characters 15-27 : For function argument 't'
src/MacroFunctions.hx:41: lines 41-46 : Missing return haxe.macro.Expr

So what should I do exactly now ? Manually create a TypePath or should it work with reification ?

Simon Krajewski

unread,
Mar 14, 2014, 2:12:54 PM3/14/14
to haxe...@googlegroups.com
Am 14.03.2014 18:25, schrieb Jimmy Delas:
> So I've updated my Haxe version to 3.1.0 but I'm still experiencing
> some errors
>
> src/MacroFunctions.hx:44: characters 15-27 : String should be
> haxe.macro.TypePath
> src/MacroFunctions.hx:44: characters 15-27 : String should be { ?sub :
> Null<String>, ?params : Array<haxe.macro.TypeParam>, pack :
> Array<String>, name : String }
> src/MacroFunctions.hx:44: characters 15-27 : String has no field name
> src/MacroFunctions.hx:44: characters 15-27 : For function argument 't'
> src/MacroFunctions.hx:41: lines 41-46 : Missing return haxe.macro.Expr
>
> So what should I do exactly now ? Manually create a TypePath or should
> it work with reification ?

That's the expected behavior. In general you can only reify the type
which is expected in the AST at that position.

Simon

Jimmy Delas

unread,
Mar 14, 2014, 7:16:02 PM3/14/14
to haxe...@googlegroups.com
Thanks Simon
Reply all
Reply to author
Forward
0 new messages