Browse Source

[typer] disallow static extensions on implicit `this`

closes #6036
Simon Krajewski 7 years ago
parent
commit
456bfb916c
3 changed files with 34 additions and 6 deletions
  1. 1 0
      extra/CHANGES.txt
  2. 0 6
      src/typing/typer.ml
  3. 33 0
      tests/unit/src/unit/issues/Issue6036.hx

+ 1 - 0
extra/CHANGES.txt

@@ -10,6 +10,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)
+	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
 	js : enums are now generated as objects instead of arrays (#6350)

+ 0 - 6
src/typing/typer.ml

@@ -372,12 +372,6 @@ let rec type_ident_raise ctx i p mode =
 		if ctx.curfun = FunStatic then raise Not_found;
 		let c , t , f = class_field ctx ctx.curclass (List.map snd ctx.curclass.cl_params) i p in
 		field_access ctx mode f (match c with None -> FAnon f | Some (c,tl) -> FInstance (c,tl,f)) t (get_this ctx p) p
-	with Not_found -> try
-		(* lookup using on 'this' *)
-		if ctx.curfun = FunStatic then raise Not_found;
-		(match using_field ctx mode (mk (TConst TThis) ctx.tthis p) i p with
-		| AKUsing (et,c,f,_) -> AKUsing (et,c,f,get_this ctx p)
-		| _ -> assert false)
 	with Not_found -> try
 		(* static variable lookup *)
 		let f = PMap.find i ctx.curclass.cl_statics in

+ 33 - 0
tests/unit/src/unit/issues/Issue6036.hx

@@ -0,0 +1,33 @@
+package unit.issues;
+
+using Lambda;
+
+private class TYPE {
+    public function new() {}
+    public function iterator():Iterator<Int> return new IntIterator(0, 1);
+}
+
+private abstract ABSTRACT(TYPE) {
+    public var array(get, never):Bool;
+    function get_array() return true;
+
+    public function new() {
+        this = new TYPE();
+	}
+
+	public function getArray() {
+        return array;
+	}
+
+	public function getThisArray() {
+        return this.array;
+    }
+}
+
+class Issue6036 extends unit.Test {
+	function test() {
+		var a = new ABSTRACT();
+		HelperMacros.typedAs(a.getArray(), true);
+		HelperMacros.typedAs(a.getThisArray(), (null : Void -> Array<Int>));
+	}
+}