Improve EventMacro error messages.

Haxe will usually prevent `EventMacro.build()` from running if there are the wrong number of type params. Therefore the "wrong number" message would usually only appear when there were the right number of params (one) and the type was wrong.
This commit is contained in:
Joseph Cloutier
2025-10-22 22:25:20 -04:00
parent 76034d97ae
commit ad52eb7848

View File

@@ -20,8 +20,17 @@ class EventMacro
typeArgs = args;
typeResult = result;
case TInst(localType, _):
Context.fatalError("Invalid number of type parameters for " + localType.toString(), Context.currentPos());
case TInst(_, []):
Context.fatalError("Expected type parameter. Did you mean Event<Void -> Void>?", Context.currentPos());
return null;
case TInst(_, [paramType]):
Context.fatalError("Expected function type. Did you mean Event<" + paramType.toString() + " -> Void>?", Context.currentPos());
return null;
case TInst(_, paramTypes):
Context.fatalError("Expected only one type parameter. Did you mean Event<"
+ paramTypes.map(haxe.macro.TypeTools.toString).join(" -> ") + ">?", Context.currentPos());
return null;
default: