Skip to content

Commit

Permalink
use real type for abstract catches, then change variable type to conc…
Browse files Browse the repository at this point in the history
…rete one (closes HaxeFoundation#2859)
  • Loading branch information
Simn committed Apr 7, 2014
1 parent 1674d07 commit bb5b76b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/unit/issues/Issue2619.hx
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down
20 changes: 20 additions & 0 deletions tests/unit/issues/Issue2859.hx
Original file line number Diff line number Diff line change
@@ -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) { }
}
5 changes: 3 additions & 2 deletions typer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bb5b76b

Please sign in to comment.