Procházet zdrojové kódy

[typer] use constrained monomorphs for static extensions

closes #8760
Simon Krajewski před 5 roky
rodič
revize
39e6c8c46f
2 změnil soubory, kde provedl 27 přidání a 7 odebrání
  1. 1 7
      src/typing/fields.ml
  2. 26 0
      tests/unit/src/unit/issues/Issue8760.hx

+ 1 - 7
src/typing/fields.ml

@@ -255,19 +255,13 @@ let rec using_field ctx mode e i p =
 		try
 			let cf = PMap.find i c.cl_statics in
 			if Meta.has Meta.NoUsing cf.cf_meta || not (can_access ctx c cf true) || (Meta.has Meta.Impl cf.cf_meta) then raise Not_found;
-			let monos = List.map (fun _ -> mk_mono()) cf.cf_params in
+			let monos = spawn_constrained_monos ctx p (fun t -> t) cf.cf_params in
 			let map = apply_params cf.cf_params monos in
 			let t = map cf.cf_type in
 			begin match follow t with
 				| TFun((_,_,(TType({t_path = ["haxe";"macro"],"ExprOf"},[t0]) | t0)) :: args,r) ->
 					if is_dynamic && follow t0 != t_dynamic then raise Not_found;
 					let e = unify_static_extension ctx e t0 p in
-					(* early constraints check is possible because e.etype has no monomorphs *)
-					List.iter2 (fun m (name,t) -> match follow t with
-						| TInst ({ cl_kind = KTypeParameter constr },_) when constr <> [] && not (has_mono m) ->
-							List.iter (fun tc -> Type.unify m (map tc)) constr
-						| _ -> ()
-					) monos cf.cf_params;
 					let et = type_module_type ctx (TClassDecl c) None p in
 					ImportHandling.mark_import_position ctx pc;
 					AKUsing (mk (TField (et,FStatic (c,cf))) t p,c,cf,e,false)

+ 26 - 0
tests/unit/src/unit/issues/Issue8760.hx

@@ -0,0 +1,26 @@
+package unit.issues;
+
+using unit.issues.Issue8760.SortStringTools;
+using unit.issues.Issue8760.SortFloatTools;
+
+private class SortStringTools {
+	public static function sorted<T:String, A:Array<T>>(arr:A) {
+		return 'sorted<T:String>()';
+	}
+  }
+
+private class SortFloatTools {
+	public static function sorted<T:Float, A:Array<T>>(arr:A) {
+		return 'sorted<T:Float>()';
+	}
+  }
+
+class Issue8760 extends Test {
+	function test() {
+		var arr1 = ["abc", "def"];
+        eq("sorted<T:String>()", arr1.sorted());
+
+        var arr2 = [123,456];
+        eq("sorted<T:Float>()", arr2.sorted());
+	}
+}