浏览代码

[typing] do not apply abstract field casts on static extensions

closes #5924
Simon Krajewski 7 年之前
父节点
当前提交
248f411153

+ 1 - 0
extra/CHANGES.txt

@@ -9,6 +9,7 @@ XXXX-XX-XX: 4.0.0-preview.4
 
 	all : implemented `for` loop unrolling (#3784)
 	all : metadata can now use `.`, e.g. `@:a.b`. This is represented as a string (#3959)
+	all : [breaking] disallow static extensions through abstract field casts (#5924)
 	js : added externs for js.Date (#6855)
 	js : respect `-D source-map` flag to generate source maps in release builds
 	js : enums are now generated as objects instead of arrays (#6350)

+ 1 - 1
src/typing/fields.ml

@@ -250,7 +250,7 @@ let rec using_field ctx mode e i p =
 			begin match follow t with
 				| TFun((_,_,(TType({t_path = ["haxe";"macro"],"ExprOf"},[t0]) | t0)) :: args,r) ->
 					if is_dynamic && follow t0 != t_dynamic then raise Not_found;
-					let e = AbstractCast.cast_or_unify_raise ctx t0 e p in
+					Type.unify e.etype t0;
 					(* early constraints check is possible because e.etype has no monomorphs *)
 					List.iter2 (fun m (name,t) -> match follow t with
 						| TInst ({ cl_kind = KTypeParameter constr },_) when constr <> [] && not (has_mono m) ->

+ 21 - 0
tests/misc/projects/Issue5924/Main.hx

@@ -0,0 +1,21 @@
+using Main;
+
+class Main {
+    static function main() {
+        0.bar();
+    }
+
+    static function bar(f:Foo)
+    	f.bar();
+}
+
+abstract Foo(String) {
+
+    inline function new(v) this = v;
+
+    @:from static function ofInt(i:Int)
+      return new Foo('$i');
+
+    public function bar() {};
+    public function baz() {};
+}

+ 2 - 0
tests/misc/projects/Issue5924/compile-fail.hxml

@@ -0,0 +1,2 @@
+-main Main
+--interp

+ 1 - 0
tests/misc/projects/Issue5924/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:5: characters 9-14 : Int has no field bar

+ 0 - 15
tests/unit/src/unit/issues/Issue2152.hx

@@ -1,15 +0,0 @@
-package unit.issues;
-
-using unit.issues.misc.Issue2152Class;
-
-private abstract MyInt(Int) {
-	public inline function new (x:Int) this = x;
-	@:to inline function toString ():String return "asString: " + this;
-}
-
-class Issue2152 extends Test {
-	function test() {
-		var z = new MyInt(1);
-		eq("asString: 1", z.passString());
-	}
-}