Browse Source

[typer] allow usage of static extensions with super (#10062)

Dmitrii Maganov 4 years ago
parent
commit
e0cda73cf1

+ 4 - 2
src/typing/fields.ml

@@ -391,6 +391,10 @@ let type_field cfg ctx e i p mode (with_type : WithType.t) =
 	in
 	let type_field_by_extension f t e =
 		let check_constant_struct = ref false in
+		let e = match t with
+			| TInst _ when e.eexpr = TConst TSuper -> { e with eexpr = TCast(mk (TConst TThis) (mk_mono()) e.epos,None) }
+			| _ -> e
+		in
 		let loop = type_field_by_list (fun (c,pc) ->
 			let cf0 = PMap.find i c.cl_statics in
 			let rec check cfl = match cfl with
@@ -449,7 +453,6 @@ let type_field cfg ctx e i p mode (with_type : WithType.t) =
 			with Not_found ->
 				type_field_by_typedef type_field_by_type_extension e td tl
 			)
-		| TInst _ when e.eexpr = TConst TSuper -> raise Not_found
 		| TMono _ -> raise Not_found
 		| TAbstract (a,tl) ->
 			(try
@@ -473,7 +476,6 @@ let type_field cfg ctx e i p mode (with_type : WithType.t) =
 		) t e in
 		match t with
 		| TType (td,tl) -> type_field_by_typedef type_field_by_module_extension e td tl
-		| TInst _ when e.eexpr = TConst TSuper -> raise Not_found
 		| TMono r ->
 			(match Monomorph.classify_constraints r with
 			| CStructural (_,is_open) when not is_open -> type_field_by_extension()

+ 0 - 24
tests/misc/projects/Issue3607/Main.hx

@@ -1,24 +0,0 @@
-using Main.Tools;
-
-class Tools {
-	@:pure(false)
-    public static function f(b:Base) {}
-
-	public static var test:String;
-}
-
-class Base {
-	public function new() { }
-}
-
-class Child extends Base {
-    public function a() {
-        super.f();
-    }
-}
-
-class Main {
-	static public function main() {
-		new Child().a();
-	}
-}

+ 0 - 1
tests/misc/projects/Issue3607/compile-fail.hxml

@@ -1 +0,0 @@
-Main

+ 0 - 1
tests/misc/projects/Issue3607/compile-fail.hxml.stderr

@@ -1 +0,0 @@
-Main.hx:16: characters 15-16 : Base has no field f

+ 28 - 0
tests/unit/src/unit/issues/Issue3607.hx

@@ -0,0 +1,28 @@
+package unit.issues;
+
+class Issue3607 extends Test {
+  function test() {
+    var foo = new Foo();
+    eq(1, foo.one());
+
+    var bar = new Bar();
+    eq(-1, bar.one());
+  }
+
+  public static function one(foo: Foo) {
+    return 1;
+  }
+}
+
+@:using(unit.issues.Issue3607)
+private class Foo {
+  public function new() {}
+}
+
+private class Bar extends Foo {
+  public function new() { super(); }
+
+  public function one() {
+    return super.one() - 2;
+  }
+}