haxe icon indicating copy to clipboard operation
haxe copied to clipboard

`haxe.macro.TypeTools.toBaseType` better error reporting

Open Antriel opened this issue 3 months ago • 2 comments

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;
	}
}

Antriel avatar Sep 22 '25 08:09 Antriel

I actually saw this before at some point when I terminated Lime from compiling

moxie-coder avatar Sep 22 '25 08:09 moxie-coder

Hmm. I'm not sure we'd want to construct a corresponding TTypeDecl there.. maybe toBaseType could return null or throw a proper exception

kLabz avatar Sep 22 '25 11:09 kLabz