Browse Source

[typer] bring back super.x failure

closes #10521
Simon Krajewski 3 years ago
parent
commit
319f812ae0

+ 13 - 15
src/typing/fields.ml

@@ -139,22 +139,12 @@ let field_access ctx mode f fh e pfield =
 		in
 		begin match fh with
 		| FHInstance(c,tl) ->
-			if e.eexpr = TConst TSuper then (match mode,f.cf_kind with
-				| MGet,Var {v_read = AccCall }
-				| MSet _,Var {v_write = AccCall }
-				| MCall _,Var {v_read = AccCall } ->
-					()
-				| MCall _, Var _ ->
-					display_error ctx "Cannot access superclass variable for calling: needs to be a proper method" pfield
-				| MCall _, _ ->
-					()
-				| MGet,Var _
-				| MSet _,Var _ when ctx.com.platform = Flash && has_class_flag c CExtern ->
-					()
-				| _, Method _ ->
+			if e.eexpr = TConst TSuper then begin match mode with
+				| MSet _ | MGet ->
 					display_error ctx "Cannot create closure on super method" pfield
-				| _ ->
-					display_error ctx "Normal variables cannot be accessed with 'super', use 'this' instead" pfield);
+				| MCall _ ->
+					()
+			end;
 			(* We need the actual class type (i.e. a potential child class) for visibility checks. *)
 			begin match follow e.etype with
 			| TInst(c,_) ->
@@ -184,6 +174,14 @@ let field_access ctx mode f fh e pfield =
 			| _ ->
 				()
 			end;
+			if e.eexpr = TConst TSuper then begin match mode with
+				| MGet | MCall _ when v.v_read = AccCall ->
+					()
+				| MSet _ when v.v_write = AccCall ->
+					()
+				| _ ->
+					display_error ctx "Normal variables cannot be accessed with 'super', use 'this' instead" pfield;
+			end;
 		| FHAnon ->
 			()
 		end;

+ 22 - 0
tests/misc/projects/Issue10521/Main.hx

@@ -0,0 +1,22 @@
+class Main {
+	static function main() {
+		new Bar(1, 2);
+	}
+}
+
+class Foo {
+	var x:Int;
+	var y:Int;
+
+	public function new(x:Int, y:Int) {
+		this.x = x;
+		this.y = y;
+	}
+}
+
+class Bar extends Foo {
+	public function new(x:Int, y:Int) {
+		super(x, y);
+		var foo = new Foo(super.x, super.y);
+	}
+}

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

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

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

@@ -0,0 +1,2 @@
+Main.hx:20: characters 27-28 : Normal variables cannot be accessed with 'super', use 'this' instead
+Main.hx:20: characters 36-37 : Normal variables cannot be accessed with 'super', use 'this' instead