Browse Source

[macro] don't try to generate removable classes

closes #9366
Simon Krajewski 5 years ago
parent
commit
b002175284
2 changed files with 39 additions and 0 deletions
  1. 6 0
      src/typing/macroContext.ml
  2. 33 0
      tests/unit/src/unit/issues/Issue9366.hx

+ 6 - 0
src/typing/macroContext.ml

@@ -417,6 +417,12 @@ and flush_macro_context mint ctx =
 	let mctx = (match ctx.g.macros with None -> die "" | Some (_,mctx) -> mctx) in
 	ctx.g.do_finalize mctx;
 	let _, types, modules = ctx.g.do_generate mctx in
+	(* Ignore removable classes: These don't have filters run on them, so trying to generate
+	   them might lead to errors (issue #9366). *)
+	let types = List.filter (function
+		| TClassDecl c when FiltersCommon.is_removable_class c -> false
+		| _ -> true
+	) types in
 	mctx.com.types <- types;
 	mctx.com.Common.modules <- modules;
 	(* we should maybe ensure that all filters in Main are applied. Not urgent atm *)

+ 33 - 0
tests/unit/src/unit/issues/Issue9366.hx

@@ -0,0 +1,33 @@
+package unit.issues;
+
+import haxe.Constraints.IMap;
+import haxe.Constraints.Constructible;
+import haxe.ds.EnumValueMap;
+
+class Issue9366 extends unit.Test {
+	function test() {
+		eq("ok", foo());
+	}
+
+	public static macro function foo() {
+		return macro $v{localVars.name()};
+	}
+
+	static final localVars:VarManager<En, EnumValueMap<En, String>> = new VarManager();
+}
+
+enum En {
+	A;
+}
+
+@:generic
+private class VarManager<K, M:IMap<K, String> & Constructible<Void->Void>> {
+	final nameToVarKey:Map<String, K> = new Map();
+
+	public function new() {}
+
+	public function name() {
+		var f = s -> nameToVarKey.exists(s);
+		return 'ok';
+	}
+}