浏览代码

remove catch type name collision check (closes #9533) (#9534)

* remove catch type name collision check (closes #9533)

the variables are properly renamed depending on the platform nowadays

* minor
Dan Korostelev 5 年之前
父节点
当前提交
2789d25c5f
共有 2 个文件被更改,包括 20 次插入12 次删除
  1. 9 12
      src/typing/typer.ml
  2. 11 0
      tests/unit/src/unit/issues/Issue9533.hx

+ 9 - 12
src/typing/typer.ml

@@ -1884,13 +1884,10 @@ and type_try ctx e1 catches with_type p =
 		| [] ->
 			()
 	in
-	let check_catch_type path params =
+	let check_catch_type_params params =
 		List.iter (fun pt ->
 			if pt != t_dynamic then error "Catch class parameter must be Dynamic" p;
-		) params;
-		(match path with
-		| x :: _ , _ -> x
-		| [] , name -> name)
+		) params
 	in
 	let catches,el = List.fold_left (fun (acc1,acc2) ((v,pv),t,e_ast,pc) ->
 		let th = Option.default (CTPath { tpackage = ["haxe"]; tname = "Exception"; tsub = None; tparams = [] },null_pos) t in
@@ -1898,17 +1895,18 @@ and type_try ctx e1 catches with_type p =
 		let rec loop t = match follow t with
 			| TInst ({ cl_kind = KTypeParameter _} as c,_) when not (TypeloadCheck.is_generic_parameter ctx c) ->
 				error "Cannot catch non-generic type parameter" p
-			| TInst ({ cl_path = path },params)
-			| TEnum ({ e_path = path },params) ->
-				check_catch_type path params,t
+			| TInst (_,params) | TEnum (_,params) ->
+				check_catch_type_params params;
+				t
 			| TAbstract(a,params) when Meta.has Meta.RuntimeValue a.a_meta ->
-				check_catch_type a.a_path params,t
+				check_catch_type_params params;
+				t
 			| TAbstract(a,tl) when not (Meta.has Meta.CoreType a.a_meta) ->
 				loop (Abstract.get_underlying_type a tl)
-			| TDynamic _ -> "",t
+			| TDynamic _ -> t
 			| _ -> error "Catch type must be a class, an enum or Dynamic" (pos e_ast)
 		in
-		let name,t2 = loop t in
+		let t2 = loop t in
 		check_unreachable acc1 t2 (pos e_ast);
 		let locals = save_locals ctx in
 		let v = add_local_with_origin ctx TVOCatchVariable v t pv in
@@ -1920,7 +1918,6 @@ and type_try ctx e1 catches with_type p =
 		if ctx.is_display_file && DisplayPosition.display_position#enclosed_in pc then ignore(TyperDisplay.display_expr ctx e_ast e DKMarked with_type pc);
 		v.v_type <- t2;
 		locals();
-		if PMap.mem name ctx.locals then error ("Local variable " ^ name ^ " is preventing usage of this type here") e.epos;
 		((v,e) :: acc1),(e :: acc2)
 	) ([],[e1]) catches in
 	let e1,catches,t = match with_type with

+ 11 - 0
tests/unit/src/unit/issues/Issue9533.hx

@@ -0,0 +1,11 @@
+package unit.issues;
+
+class Issue9533 extends unit.Test {
+	function test() {
+		var unit = "fail";
+		try throw new Error("success") catch (e:Error) unit = e.message;
+		eq("success", unit);
+	}
+}
+
+private class Error extends haxe.Exception {}