Browse Source

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

Aleksandr Kuzmenko 4 years ago
parent
commit
04383c60bf
3 changed files with 15 additions and 0 deletions
  1. 1 0
      extra/CHANGES.txt
  2. 1 0
      src/generators/genlua.ml
  3. 13 0
      tests/unit/src/unit/issues/Issue10343.hx

+ 1 - 0
extra/CHANGES.txt

@@ -10,6 +10,7 @@
 	cs/java : fixed rest arguments for cases when only one argument is provided (#10315)
 	php : fixed type of `php.db.PDO.ATTR_DRIVER_NAME` (#10319)
 	eval : fixed signature of `eval.luv.Tcp.noDelay` method
+	lua : fixed `string.length` when `string` has type of a type parameter constrained to `String` (#10343)
 
 2021-07-01 4.2.3:
 

+ 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;
+	}
+}