فهرست منبع

[typer] use `cast_or_unify` for ETry too

closes #8257
Simon Krajewski 6 سال پیش
والد
کامیت
478c8f4c48
2فایلهای تغییر یافته به همراه23 افزوده شده و 6 حذف شده
  1. 9 6
      src/typing/typer.ml
  2. 14 0
      tests/unit/src/unit/issues/Issue8257.hx

+ 9 - 6
src/typing/typer.ml

@@ -1857,13 +1857,16 @@ and type_try ctx e1 catches with_type p =
 		if PMap.mem name ctx.locals then error ("Local variable " ^ name ^ " is preventing usage of this type here") e.epos;
 		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)
 		((v,e) :: acc1),(e :: acc2)
 	) ([],[e1]) catches in
 	) ([],[e1]) catches in
-	let t = match with_type with
-		| WithType.NoValue -> ctx.t.tvoid
-		| WithType.Value _ -> unify_min ctx el
-		| WithType.WithType(t,_) when (match follow t with TMono _ -> true | _ -> false) -> unify_min ctx el
+	let e1,catches,t = match with_type with
+		| WithType.NoValue -> e1,catches,ctx.t.tvoid
+		| WithType.Value _ -> e1,catches,unify_min ctx el
+		| WithType.WithType(t,_) when (match follow t with TMono _ -> true | _ -> false) -> e1,catches,unify_min ctx el
 		| WithType.WithType(t,_) ->
 		| WithType.WithType(t,_) ->
-			List.iter (fun e -> unify ctx e.etype t e.epos) el;
-			t
+			let e1 = AbstractCast.cast_or_unify ctx t e1 e1.epos in
+			let catches = List.map (fun (v,e) ->
+				v,AbstractCast.cast_or_unify ctx t e e.epos
+			) catches in
+			e1,catches,t
 	in
 	in
 	mk (TTry (e1,List.rev catches)) t p
 	mk (TTry (e1,List.rev catches)) t p
 
 

+ 14 - 0
tests/unit/src/unit/issues/Issue8257.hx

@@ -0,0 +1,14 @@
+package unit.issues;
+
+import utest.Assert;
+private abstract Dyn(Dynamic) from Dynamic {
+	@:to function toDynamic():Dynamic return this;
+}
+
+class Issue8257 extends unit.Test {
+	function test() {
+		var value:Dyn = "s";
+		(try value catch (pokemon:Dynamic) null : String);
+		Assert.pass();
+	}
+}