2
0
Эх сурвалжийг харах

use abstract `this` for properties only if they are not static (closes #3554)

Simon Krajewski 10 жил өмнө
parent
commit
4546bce6fe

+ 20 - 0
tests/unit/src/unit/issues/Issue3554.hx

@@ -0,0 +1,20 @@
+package unit.issues;
+
+private abstract A(Int)
+{
+    public static var a(get,never):Int;
+    private static function get_a()
+        return(1 << x);
+
+    public static var x(get,never):Int;
+    static var _x:Int = 4;
+    inline static function get_x()
+        return _x;
+}
+
+
+class Issue3554 extends Test {
+	function test() {
+		eq(16, A.a);
+	}
+}

+ 7 - 1
typer.ml

@@ -1163,6 +1163,12 @@ let field_access ctx mode f fmode t e p =
 				normal()
 		| AccCall ->
 			let m = (match mode with MSet -> "set_" | _ -> "get_") ^ f.cf_name in
+			let is_abstract_this_access () = match e.eexpr,ctx.curfun with
+				| TTypeExpr (TClassDecl ({cl_kind = KAbstractImpl _} as c)),(FunMemberAbstract | FunMemberAbstractLocal) ->
+					c == ctx.curclass
+				| _ ->
+					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
 				let prefix = (match ctx.com.platform with Flash when Common.defined ctx.com Define.As3 -> "$" | _ -> "") in
 				if is_extern_field f then begin
@@ -1170,7 +1176,7 @@ let field_access ctx mode f fmode t e p =
 					display_error ctx "Add @:isVar here to enable it" f.cf_pos;
 				end;
 				AKExpr (mk (TField (e,if prefix = "" then fmode else FDynamic (prefix ^ f.cf_name))) t p)
-			else if (match e.eexpr with TTypeExpr (TClassDecl ({cl_kind = KAbstractImpl _} as c)) when c == ctx.curclass -> true | _ -> false) then begin
+			else if is_abstract_this_access() then begin
 				let this = get_this ctx p in
 				if mode = MSet then begin
 					let c,a = match ctx.curclass with {cl_kind = KAbstractImpl a} as c -> c,a | _ -> assert false in