Browse Source

[lua] detect of a string type on type parameters (fixes #10343)

Aleksandr Kuzmenko 4 years ago
parent
commit
bc7efc9a59
2 changed files with 14 additions and 0 deletions
  1. 1 0
      src/generators/genlua.ml
  2. 13 0
      tests/unit/src/unit/issues/Issue10343.hx

+ 1 - 0
src/generators/genlua.ml

@@ -273,6 +273,7 @@ let mk_mr_select com e ecall name =
 (* from genphp *)
 let rec is_string_type t =
     match follow t with
+    | TInst ({cl_kind = KTypeParameter constraints}, _) -> List.exists is_string_type constraints
     | TInst ({cl_path = ([], "String")}, _) -> true
     | TAnon a ->
         (match !(a.a_status) with

+ 13 - 0
tests/unit/src/unit/issues/Issue10343.hx

@@ -0,0 +1,13 @@
+package unit.issues;
+
+class Issue10343 extends Test {
+	function test() {
+		final str = "hello";
+		eq(str.length, foo(str));
+	}
+
+	@:pure(false)
+	public function foo<T:String>(str:T):Int {
+		return str.length;
+	}
+}