diff --git a/tests/unit/issues/Issue2619.hx b/tests/unit/issues/Issue2619.hx index 2253490f57f..e8735ef58a3 100644 --- a/tests/unit/issues/Issue2619.hx +++ b/tests/unit/issues/Issue2619.hx @@ -1,7 +1,7 @@ package unit.issues; import unit.Test; -private abstract A(String) { +private abstract A(String) to String { public function new(s) this = s; } diff --git a/tests/unit/issues/Issue2859.hx b/tests/unit/issues/Issue2859.hx new file mode 100644 index 00000000000..fe83c70ce4e --- /dev/null +++ b/tests/unit/issues/Issue2859.hx @@ -0,0 +1,20 @@ +package unit.issues; + +private abstract Error(String) { + public function new(message:String) { + this = message; + } +} + +class Issue2859 extends Test { + function test() { + try { + throw new Error("hello"); + } catch (e:Error) { + unit.TestType.typedAs(e, (null:Error)); + func(e); + } + } + + static function func(e:Error) { } +} \ No newline at end of file diff --git a/typer.ml b/typer.ml index 52d4675584e..4069120346b 100644 --- a/typer.ml +++ b/typer.ml @@ -2823,12 +2823,13 @@ and type_expr ctx (e,p) (with_type:with_type) = | TDynamic _ -> "",t | _ -> error "Catch type must be a class, an enum or Dynamic" (pos e) in - let name,t = loop t in + let name,t2 = loop t in if v.[0] = '$' then display_error ctx "Catch variable names starting with a dollar are not allowed" p; - check_unreachable acc t (pos e); + check_unreachable acc t2 (pos e); let locals = save_locals ctx in let v = add_local ctx v t in let e = type_expr ctx e with_type in + v.v_type <- t2; locals(); if with_type <> NoValue then unify ctx e.etype e1.etype e.epos; if PMap.mem name ctx.locals then error ("Local variable " ^ name ^ " is preventing usage of this type here") e.epos;