فهرست منبع

Fix EReg use as type parameter (#6977)

Ben Morris 7 سال پیش
والد
کامیت
f2903e1c49
2فایلهای تغییر یافته به همراه14 افزوده شده و 4 حذف شده
  1. 3 1
      src/typing/typeload.ml
  2. 11 3
      tests/unit/src/unit/issues/Issue6952.hx

+ 3 - 1
src/typing/typeload.ml

@@ -3806,7 +3806,9 @@ let make_generic ctx ps pt p =
 			let ident_safe = Str.global_substitute (Str.regexp "[^a-zA-Z0-9_]") subst in
 			let ident_safe = Str.global_substitute (Str.regexp "[^a-zA-Z0-9_]") subst in
 			let s_type_path_underscore (p,s) = match p with [] -> s | _ -> String.concat "_" p ^ "_" ^ s in
 			let s_type_path_underscore (p,s) = match p with [] -> s | _ -> String.concat "_" p ^ "_" ^ s in
 			let rec loop top t = match follow t with
 			let rec loop top t = match follow t with
-				| TInst(c,tl) -> (ident_safe (s_type_path_underscore c.cl_path)) ^ (loop_tl tl)
+				| TInst(c,tl) -> (match c.cl_kind with
+					| KExpr e -> ident_safe (Ast.s_expr e)
+					| _ -> (ident_safe (s_type_path_underscore c.cl_path)) ^ (loop_tl tl))
 				| TEnum(en,tl) -> (s_type_path_underscore en.e_path) ^ (loop_tl tl)
 				| TEnum(en,tl) -> (s_type_path_underscore en.e_path) ^ (loop_tl tl)
 				| TAnon(a) -> "anon_" ^ String.concat "_" (PMap.foldi (fun s f acc -> (s ^ "_" ^ (loop false (follow f.cf_type))) :: acc) a.a_fields [])
 				| TAnon(a) -> "anon_" ^ String.concat "_" (PMap.foldi (fun s f acc -> (s ^ "_" ^ (loop false (follow f.cf_type))) :: acc) a.a_fields [])
 				| TAbstract(a,tl) -> (s_type_path_underscore a.a_path) ^ (loop_tl tl)
 				| TAbstract(a,tl) -> (s_type_path_underscore a.a_path) ^ (loop_tl tl)

+ 11 - 3
tests/unit/src/unit/issues/Issue6952.hx

@@ -3,7 +3,7 @@ package unit.issues;
 @:generic class Issue6952TestClass<@:const T> {
 @:generic class Issue6952TestClass<@:const T> {
 	public function new() {}
 	public function new() {}
 	public function foo() {
 	public function foo() {
-		T;
+		return T;
 	}
 	}
 }
 }
 
 
@@ -11,6 +11,14 @@ class Issue6952 extends Test {
 
 
 	function test() {
 	function test() {
 		var x = new Issue6952TestClass<"hello world">();
 		var x = new Issue6952TestClass<"hello world">();
-		x.foo();
+		eq("hello world", x.foo());
+
+		var r1:EReg = new Issue6952TestClass<~/a/>().foo();
+		var r2:EReg = new Issue6952TestClass<~/b/>().foo();
+
+		eq(true, r1.match("a"));
+		eq(false, r1.match("b"));
+		eq(false, r2.match("a"));
+		eq(true, r2.match("b"));
 	}
 	}
-}
+}