Browse Source

[java/cs] Make sure to collect the right type parameters on anonymous functions

Closes #5793
Cauê Waneck 8 years ago
parent
commit
3d4e2be390

+ 7 - 0
src/generators/gencommon/closuresToClass.ml

@@ -351,6 +351,13 @@ let get_captured expr =
 let configure gen ft =
 let configure gen ft =
 
 
 	let handle_anon_func fexpr tfunc mapinfo delegate_type : texpr * (tclass * texpr list) =
 	let handle_anon_func fexpr tfunc mapinfo delegate_type : texpr * (tclass * texpr list) =
+		let fexpr = match fexpr.eexpr with
+			| TFunction(_) ->
+				{ fexpr with eexpr = TFunction(tfunc) }
+			| _ ->
+				gen.gcon.error "Function expected" fexpr.epos;
+				fexpr
+		in
 		let in_unsafe = mapinfo.in_unsafe || match gen.gcurrent_class, gen.gcurrent_classfield with
 		let in_unsafe = mapinfo.in_unsafe || match gen.gcurrent_class, gen.gcurrent_classfield with
 			| Some c, _ when Meta.has Meta.Unsafe c.cl_meta -> true
 			| Some c, _ when Meta.has Meta.Unsafe c.cl_meta -> true
 			| _, Some cf when Meta.has Meta.Unsafe cf.cf_meta -> true
 			| _, Some cf when Meta.has Meta.Unsafe cf.cf_meta -> true

+ 24 - 0
tests/unit/src/unit/issues/Issue5793.hx

@@ -0,0 +1,24 @@
+package unit.issues;
+
+class Issue5793 extends Test {
+  public function test() {
+    function run1() {
+      function foo <T> (expected:Array<T>, a:T) {
+        eq(expected[0], a);
+      }
+      foo([2], 2);
+    }
+    run1();
+
+    function run2() {
+      function bar<A>(expected:Array<A>, a:A) {
+        function baz<B>(expected:Array<B>, b:B) {
+          eq(expected[0], b);
+        }
+        baz(expected,a);
+      }
+      bar([42],42);
+    }
+    run2();
+  }
+}