Using macro type reification inside macro block

33 views
Skip to first unread message

Garrett Hopper

unread,
Sep 6, 2016, 3:58:46 PM9/6/16
to Haxe
Should something like this be possible?

macro {
   
var test: ${macro: ?String} = null;
}

It seems like that should work, but it doesn't.

The actual use case involved dynamically creating anonymous types.
I'm currently doing this through string concatenatin, but it's pretty ugly:

exprs.push("var test: {" +
    list
.map(function(test): String return '${test.name}: ${test.type}').join(", ") +
   
"} = {" + list.map(function(test): String return '${test.name}: null').join(", ") + "}");
Or at least something similar to that.

Later on:
Context.parse(expr, Context.currentPos());


Thanks!

Garrett Hopper

unread,
Sep 6, 2016, 4:09:53 PM9/6/16
to Haxe
Note: this does work with a variable:

var type = macro: ?String;

var a = macro {
   
var b: $type = null;
}

However, how could this be done with an array map in an anonymous type?

var type = macro: {
    $a
{list.map(function(test) return test.name: test.type)}
}

Perhaps something like this? I don't entirely understand the $a reification.
Reply all
Reply to author
Forward
0 new messages