Explorar o código

[typer] make sure abstracts are built when finding fields

closes #6873
Simon Krajewski %!s(int64=7) %!d(string=hai) anos
pai
achega
fad0fc4d93

+ 10 - 0
src/core/abstract.ml

@@ -2,6 +2,10 @@ open Meta
 open Type
 open Error
 
+let build_abstract a = match a.a_impl with
+	| Some c -> ignore(c.cl_build())
+	| None -> ()
+
 let has_direct_to ab pl b =
 	List.exists (unify_to ab pl ~allow_transitive_cast:false b) ab.a_to
 
@@ -9,12 +13,16 @@ let has_direct_from ab pl a b =
 	List.exists (unify_from ab pl a ~allow_transitive_cast:false b) ab.a_from
 
 let find_field_to ab pl b =
+	build_abstract ab;
 	List.find (unify_to_field ab pl b) ab.a_to_field
 
 let find_field_from ab pl a b =
+	build_abstract ab;
 	List.find (unify_from_field ab pl a b) ab.a_from_field
 
 let find_to_from f ab_left tl_left ab_right tl_right tleft tright =
+	build_abstract ab_left;
+	build_abstract ab_right;
 	if has_direct_to ab_right tl_right tleft || has_direct_from ab_left tl_left tright tleft then
 		raise Not_found
 	else
@@ -22,6 +30,7 @@ let find_to_from f ab_left tl_left ab_right tl_right tleft tright =
 		with Not_found -> f ab_left tl_left (fun () -> find_field_from ab_left tl_left tright tleft)
 
 let find_to ab pl b =
+	build_abstract ab;
 	if follow b == t_dynamic then
 		List.find (fun (t,_) -> follow t == t_dynamic) ab.a_to_field
 	else if has_direct_to ab pl b then
@@ -30,6 +39,7 @@ let find_to ab pl b =
 		find_field_to ab pl b
 
 let find_from ab pl a b =
+	build_abstract ab;
 	if follow a == t_dynamic then
 		List.find (fun (t,_) -> follow t == t_dynamic) ab.a_from_field
 	else if has_direct_from ab pl a b then

+ 12 - 0
tests/unit/src/unit/issues/Issue6873.hx

@@ -0,0 +1,12 @@
+package unit.issues;
+
+@:build(unit.issues.misc.Issue6873Macro.build())
+private class C { }
+
+
+class Issue6873 extends unit.Test {
+	function test() {
+		var expected = "TType(Map,[TInst(String,[]),TAbstract(Int,[])])TInst(haxe.ds.StringMap,[TAbstract(Int,[])])";
+		eq(expected, C.result);
+	}
+}

+ 26 - 0
tests/unit/src/unit/issues/misc/Issue6873Macro.hx

@@ -0,0 +1,26 @@
+package unit.issues.misc;
+
+import haxe.macro.Context;
+import haxe.macro.Expr;
+import haxe.macro.ComplexTypeTools;
+import haxe.macro.TypeTools;
+
+class Issue6873Macro {
+    macro public static function build():Array<Field> {
+        var fields = Context.getBuildFields();
+
+        var m = ComplexTypeTools.toType(macro : Map<String, Int>);
+        var last = "";
+		var s = "";
+        do {
+            s += m;
+            last = Std.string(m);
+            m = TypeTools.followWithAbstracts(m, false);
+        } while (last != Std.string(m));
+
+		fields.push((macro class X {
+			static public var result = $v{s};
+		}).fields[0]);
+        return fields;
+    }
+}