浏览代码

use real type for abstract catches, then change variable type to concrete one (closes #2859)

Simon Krajewski 11 年之前
父节点
当前提交
bb5b76be0a
共有 3 个文件被更改,包括 24 次插入3 次删除
  1. 1 1
      tests/unit/issues/Issue2619.hx
  2. 20 0
      tests/unit/issues/Issue2859.hx
  3. 3 2
      typer.ml

+ 1 - 1
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;
 }
 

+ 20 - 0
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) { }
+}

+ 3 - 2
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;