Skip to content

Commit

Permalink
[typer] disallow static extensions on implicit this
Browse files Browse the repository at this point in the history
closes #6036
  • Loading branch information
Simn committed Jun 6, 2018
1 parent 248f411 commit 456bfb9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions extra/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions src/typing/typer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/src/unit/issues/Issue6036.hx
Original file line number Diff line number Diff line change
@@ -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>));
}
}

0 comments on commit 456bfb9

Please sign in to comment.