haxe
haxe copied to clipboard
`haxe.macro.TypeTools.toBaseType` better error reporting
If toBaseType (or well, toModuleType, so actually type_to_module_type) gets called with unsupported type, the error is just:
[ERROR] (unknown position)
| Stdlib.Exit
It would be nice if the error had a message and proper position. Sample code:
// Main.hx
class Test {
static function main() {
var a:Foo<Test>; // Good.
var b:Foo<{anonType:Bool}>; // Not good.
}
}
@:genericBuild(Macro.build()) class Foo<T> {}
// Macro.hx
class Macro {
static public function build() {
switch (haxe.macro.Context.getLocalType()) {
case TInst(_, [t1]):
trace(haxe.macro.TypeTools.toBaseType(t1));
case t:
}
return null;
}
}
I actually saw this before at some point when I terminated Lime from compiling
Hmm. I'm not sure we'd want to construct a corresponding TTypeDecl there.. maybe toBaseType could return null or throw a proper exception