Explorar el Código

[typer] use constrained monomorphs for overloads

closes #6065
Simon Krajewski hace 5 años
padre
commit
cffc0f1f26

+ 6 - 2
src/typing/calls.ml

@@ -232,7 +232,8 @@ let unify_call_args ctx el args r p inline force_inline =
 
 let unify_field_call ctx fa el args ret p inline =
 	let map_cf cf0 map cf =
-		let t = map (monomorphs cf.cf_params cf.cf_type) in
+		let monos = spawn_constrained_monos ctx p map cf.cf_params in
+		let t = map (apply_params cf.cf_params monos cf.cf_type) in
 		begin match cf.cf_expr,cf.cf_kind with
 		| None,Method MethInline when not ctx.com.config.pf_overload ->
 			(* This is really awkward and shouldn't be here. We'll keep it for
@@ -260,7 +261,10 @@ let unify_field_call ctx fa el args ret p inline =
 			let cfl = if cf.cf_name = "new" || not (Meta.has Meta.Overload cf.cf_meta && ctx.com.config.pf_overload) then
 				List.map (map_cf cf map) cf.cf_overloads
 			else
-				List.map (fun (t,cf) -> map (monomorphs cf.cf_params t),cf) (Overloads.get_overloads c cf.cf_name)
+				List.map (fun (t,cf) ->
+					let monos = spawn_constrained_monos ctx p map cf.cf_params in
+					map (apply_params cf.cf_params monos t),cf
+				) (Overloads.get_overloads c cf.cf_name)
 			in
 			(TFun(args,ret),cf) :: cfl,Some c,cf,(fun cf -> FInstance(c,tl,cf))
 		| FClosure(co,cf) ->

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

@@ -0,0 +1,11 @@
+extern class C {
+    @:overload(function<T:Int>(t:T):Void {})
+    static function f():Void;
+}
+
+class Main {
+    static function main() {
+        C.f("hi");
+        C.f({});
+    }
+}

+ 3 - 0
tests/misc/projects/Issue6065/compile-fail.hxml

@@ -0,0 +1,3 @@
+--main Main
+-neko neko.n
+--no-output

+ 16 - 0
tests/misc/projects/Issue6065/compile-fail.hxml.stderr

@@ -0,0 +1,16 @@
+Main.hx:8: characters 9-18 : Could not find a suitable overload, reasons follow
+Main.hx:8: characters 9-18 : Overload resolution failed for () -> Void
+Main.hx:8: characters 13-17 : Too many arguments
+Main.hx:8: characters 9-18 : Overload resolution failed for (t : f.T) -> Void
+Main.hx:8: characters 13-17 : Constraint check failure for f.T
+Main.hx:8: characters 13-17 : String should be Int
+Main.hx:8: characters 13-17 : For function argument 't'
+Main.hx:8: characters 9-18 : End of overload failure reasons
+Main.hx:9: characters 9-16 : Could not find a suitable overload, reasons follow
+Main.hx:9: characters 9-16 : Overload resolution failed for () -> Void
+Main.hx:9: characters 13-15 : Too many arguments
+Main.hx:9: characters 9-16 : Overload resolution failed for (t : f.T) -> Void
+Main.hx:9: characters 13-15 : Constraint check failure for f.T
+Main.hx:9: characters 13-15 : { } should be Int
+Main.hx:9: characters 13-15 : For function argument 't'
+Main.hx:9: characters 9-16 : End of overload failure reasons

+ 22 - 0
tests/unit/src/unit/TestConstrainedMonomorphs.hx

@@ -35,6 +35,22 @@ private class DetectiveHaxeImplementation {
 }
 #end
 
+#if neko
+@:native("unit.Issue6065Extern")
+extern class Issue6065Extern {
+    @:overload(function(t:String):String {})
+    static function f<T:Int>(t:T):T;
+}
+
+@:native("unit.Issue6065Extern")
+@:keep
+class Issue6065Implementation {
+    static public function f<T>(t:T) {
+		return t;
+	}
+}
+#end
+
 class TestConstrainedMonomorphs extends Test {
 
 	function infer(arg) {
@@ -77,4 +93,10 @@ class TestConstrainedMonomorphs extends Test {
 		return null;
 	}
 
+	#if neko
+	public function testIssue6065() {
+		eq("hi", Issue6065Extern.f("hi"));
+	}
+	#end
+
 }