COMMUNITY

Macro type definition Const params

Hej !
I wanted to do this thing in a macro where resPath is a String argument :

var cl	= macro class TextsProxy extends haxe.xml.Proxy<macro $v{ resPath }, String>{
	public static var __res	= $v{ resPath };
}

But compiler doesn’t take $v{ resPath }as type parameter of haxe.xml.Proxy (it does’nt complain for the form but then can’t find the xml).
The only workaround I found is that :

var cl	= macro class TextsProxy extends haxe.xml.Proxy<"foo", String>{
	public static var __res	= $v{ resPath };
}
switch( cl.kind ){
	case TDClass(superClass, interfaces, isInterface, isFinal):
		superClass.params[ 0 ] = TPExpr( macro $v{ resPath } );
	case _ :
}

Is it possible to do it in the 1st way please ?

This isn’t exactly the first way but I think it’s (subjectively) cleaner than your workaround

var tp : TypePath = {
	pack: ["haxe","xml"],
	name: "Proxy",
	params: [TPExpr(macro $v{resPath}), TPType(macro :String)]
};
var cl = macro class TextsProxy extends $tp {
	public static var __res	= $v{ resPath };
}

maybe it helps.

1 Like

Thanks Mario !
Yes it’s cleaner.
But if someone has a solution for the 1st way, just to know if something like that is possible in fact.