Browse Source

fix static @:op([]) functions (closes #9347)

Aleksandr Kuzmenko 5 years ago
parent
commit
bdcd85c1cb

+ 8 - 3
src/context/abstractCast.ml

@@ -110,7 +110,8 @@ and cast_or_unify ctx tleft eright p =
 let find_array_access_raise ctx a pl e1 e2o p =
 let find_array_access_raise ctx a pl e1 e2o p =
 	let is_set = e2o <> None in
 	let is_set = e2o <> None in
 	let ta = apply_params a.a_params pl a.a_this in
 	let ta = apply_params a.a_params pl a.a_this in
-	let rec loop cfl = match cfl with
+	let rec loop cfl =
+		match cfl with
 		| [] -> raise Not_found
 		| [] -> raise Not_found
 		| cf :: cfl ->
 		| cf :: cfl ->
 			let monos = List.map (fun _ -> mk_mono()) cf.cf_params in
 			let monos = List.map (fun _ -> mk_mono()) cf.cf_params in
@@ -122,10 +123,14 @@ let find_array_access_raise ctx a pl e1 e2o p =
 					| _ -> ()
 					| _ -> ()
 				) monos cf.cf_params;
 				) monos cf.cf_params;
 			in
 			in
+			let get_ta() =
+				if has_meta Meta.Impl cf.cf_meta then ta
+				else TAbstract(a,pl)
+			in
 			match follow (map cf.cf_type) with
 			match follow (map cf.cf_type) with
 			| TFun([(_,_,tab);(_,_,ta1);(_,_,ta2)],r) as tf when is_set ->
 			| TFun([(_,_,tab);(_,_,ta1);(_,_,ta2)],r) as tf when is_set ->
 				begin try
 				begin try
-					Type.unify tab ta;
+					Type.unify tab (get_ta());
 					let e1 = cast_or_unify_raise ctx ta1 e1 p in
 					let e1 = cast_or_unify_raise ctx ta1 e1 p in
 					let e2o = match e2o with None -> None | Some e2 -> Some (cast_or_unify_raise ctx ta2 e2 p) in
 					let e2o = match e2o with None -> None | Some e2 -> Some (cast_or_unify_raise ctx ta2 e2 p) in
 					check_constraints();
 					check_constraints();
@@ -135,7 +140,7 @@ let find_array_access_raise ctx a pl e1 e2o p =
 				end
 				end
 			| TFun([(_,_,tab);(_,_,ta1)],r) as tf when not is_set ->
 			| TFun([(_,_,tab);(_,_,ta1)],r) as tf when not is_set ->
 				begin try
 				begin try
-					Type.unify tab ta;
+					Type.unify tab (get_ta());
 					let e1 = cast_or_unify_raise ctx ta1 e1 p in
 					let e1 = cast_or_unify_raise ctx ta1 e1 p in
 					check_constraints();
 					check_constraints();
 					cf,tf,r,e1,None
 					cf,tf,r,e1,None

+ 19 - 0
tests/misc/projects/Issue9347/Main.hx

@@ -0,0 +1,19 @@
+class Main {
+	static function main() {
+		(1:A1<String>)['foo'];
+		(1:A2<Int>)['bar'];
+		(1:A2<Main>)['baz'];
+	}
+}
+
+abstract A1<T>(Int) from Int {
+	@:op([]) static function get<S>(instance: A1<S>, key: String): String {
+		return '${instance}${key}';
+	}
+}
+
+abstract A2<T>(Int) from Int {
+	@:op([]) static function get(instance: A2<Int>, key: String): String {
+		return '${instance}${key}';
+	}
+}

+ 1 - 0
tests/misc/projects/Issue9347/compile-fail.hxml

@@ -0,0 +1 @@
+-main Main

+ 1 - 0
tests/misc/projects/Issue9347/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:5: characters 3-22 : No @:arrayAccess function accepts argument of String