Browse Source

[typer] revert static extension abstract cast change for now

see #5924
closes #7142
Simon Krajewski 7 years ago
parent
commit
8fea07a9d1

+ 0 - 1
extra/CHANGES.txt

@@ -10,7 +10,6 @@ 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)
 	all : [breaking] disallow static extensions on implicit `this` (#6036)
 	js : added externs for js.Date (#6855)
 	js : respect `-D source-map` flag to generate source maps in release builds

+ 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;
-					Type.unify e.etype t0;
+					let e = AbstractCast.cast_or_unify_raise ctx t0 e p in
 					(* 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) ->

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

@@ -1,21 +0,0 @@
-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() {};
-}

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

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

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

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

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

@@ -0,0 +1,15 @@
+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());
+	}
+}