2
0
Эх сурвалжийг харах

[macro] error if @:genericBuild meta is removed during building
fixes #9391

Aleksandr Kuzmenko 5 жил өмнө
parent
commit
f82bc96043

+ 1 - 0
extra/CHANGES.txt

@@ -3,6 +3,7 @@
 	Bugfixes:
 
 	flash : fixed var shadowing issue for variables captured in a closure inside of a loop (#9624)
+	macro : fixed compiler crash if `@:genericBuild` meta is removed by a macro during building (#9391)
 	nullsafety: fixed `@:nullSafety(Off)` in closures inside of constructors (#9643)
 	nullsafety: fixed "Type not found NullSafetyMode_Impl_" (#9483)
 

+ 6 - 1
src/typing/instanceBuilder.ml

@@ -46,7 +46,12 @@ let build_macro_type ctx pl p =
 	t
 
 let build_macro_build ctx c pl cfl p =
-	let path, field, args = match Meta.get Meta.GenericBuild c.cl_meta with
+	let path, field, args =
+		let build_expr =
+			try Meta.get Meta.GenericBuild c.cl_meta
+			with Not_found -> error ((s_type_path c.cl_path) ^ " is missing @:genericBuild meta. Was it removed by a macro?") p
+		in
+		match build_expr with
 		| _,[ECall(e,args),_],_ -> get_macro_path ctx e args p
 		| _ -> error "genericBuild requires a single expression call parameter" p
 	in

+ 10 - 0
tests/misc/projects/Issue9391/Macro.hx

@@ -0,0 +1,10 @@
+import haxe.macro.Context;
+import haxe.macro.Expr;
+
+class Macro {
+	public static function build():ComplexType {
+		var localClass = Context.getLocalClass().get();
+		localClass.meta.remove(":genericBuild");
+		return null;
+	}
+}

+ 11 - 0
tests/misc/projects/Issue9391/Main.hx

@@ -0,0 +1,11 @@
+@:genericBuild(Macro.build())
+class Foo<T> {
+
+}
+
+class Main {
+	static function main() {
+		var a:Foo<String>;
+		var b:Foo<Int>;
+	}
+}

+ 1 - 0
tests/misc/projects/Issue9391/compile-fail.hxml

@@ -0,0 +1 @@
+--main Main

+ 1 - 0
tests/misc/projects/Issue9391/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:8: characters 9-20 : Foo is missing @:genericBuild meta. Was it removed by a macro?