Browse Source

[cs] always substitute `Null<T>` with `object` in type params (fixes #8664)

Aleksandr Kuzmenko 6 years ago
parent
commit
d06ded2507

+ 2 - 2
src/generators/gencs.ml

@@ -998,12 +998,12 @@ let generate con =
 			let ret t =
 				let t_changed = real_type stack t in
 				match is_hxgeneric, t_changed with
-				| false, _ -> t
 				(*
 					Because Null<> types need a special compiler treatment for many operations (e.g. boxing/unboxing),
 					Null<> type parameters will be transformed into Dynamic.
 				*)
-				| true, TInst ( { cl_path = (["haxe";"lang"], "Null") }, _ ) -> dynamic_anon
+				| _, TInst ( { cl_path = (["haxe";"lang"], "Null") }, _ ) -> dynamic_anon
+				| false, _ -> t
 				| true, TInst ( { cl_path = ([], "String") }, _ ) -> t
 				| true, TInst ( { cl_kind = KTypeParameter _ }, _ ) -> t
 				| true, TInst _

+ 25 - 0
tests/misc/cs/projects/Issue8664/Main.hx

@@ -0,0 +1,25 @@
+import cs.NativeArray;
+
+class Main {
+	public static function main() {
+		new Arr<String>().map(function(v) return Std.parseInt(v));
+	}
+}
+
+class Arr<T> {
+	var __a:NativeArray<T>;
+
+	public function new() {}
+
+	public inline function map<S>(f:T->S) {
+		new Arr<S>().__unsafe_set(f(__unsafe_get()));
+	}
+
+	inline function __unsafe_get():T {
+		return __a[0];
+	}
+
+	inline function __unsafe_set(val:T):T {
+		return __a[0] = val;
+	}
+}

+ 2 - 0
tests/misc/cs/projects/Issue8664/compile.hxml

@@ -0,0 +1,2 @@
+-main Main
+-cs bin