Browse Source

Fix #6375 (#6376)

* also check tempvar'd this field access when typing getter/setter (closes #6375)

* add test
Dan Korostelev 8 years ago
parent
commit
833e3a2c37
2 changed files with 33 additions and 1 deletions
  1. 1 1
      src/typing/typer.ml
  2. 32 0
      tests/unit/src/unit/issues/Issue6375.hx

+ 1 - 1
src/typing/typer.ml

@@ -1053,7 +1053,7 @@ let field_access ctx mode f fmode t e p =
 				| _ ->
 					false
 			in
-			if m = ctx.curfield.cf_name && (match e.eexpr with TConst TThis -> true | TTypeExpr (TClassDecl c) when c == ctx.curclass -> true | _ -> false) then
+			if m = ctx.curfield.cf_name && (match e.eexpr with TConst TThis -> true | TLocal v -> Option.map_default (fun vthis -> v == vthis) false ctx.vthis | TTypeExpr (TClassDecl c) when c == ctx.curclass -> true | _ -> false) then
 				let prefix = (match ctx.com.platform with Flash when Common.defined ctx.com Define.As3 -> "$" | _ -> "") in
 				if is_extern_field f then begin
 					display_error ctx "This field cannot be accessed because it is not a real variable" p;

+ 32 - 0
tests/unit/src/unit/issues/Issue6375.hx

@@ -0,0 +1,32 @@
+package unit.issues;
+
+class Issue6375 extends Test {
+	var memberField(default,set):Int;
+	static var staticField(default,set):Int;
+
+	static var rollback:Void->Void;
+
+	function set_memberField(_) {
+		memberField = 1;
+		rollback = () -> memberField = 3;
+		return memberField;
+	}
+
+	static function set_staticField(_) {
+		staticField = 2;
+		rollback = () -> staticField = 4;
+		return staticField;
+	}
+
+	function test() {
+		memberField = 42;
+		eq(memberField, 1);
+		rollback();
+		eq(memberField, 3);
+
+		staticField = 42;
+		eq(staticField, 2);
+		rollback();
+		eq(staticField, 4);
+	}
+}