浏览代码

disallow explicit `super()` calls to pseudo-constructor as well

Simon Krajewski 10 年之前
父节点
当前提交
8a276c8c54
共有 2 个文件被更改,包括 10 次插入9 次删除
  1. 9 9
      tests/unit/src/unit/issues/Issue3596.hx
  2. 1 0
      typer.ml

+ 9 - 9
tests/unit/src/unit/issues/Issue3596.hx

@@ -8,12 +8,12 @@ private class ClassWithInitButNoConstructorChild extends ClassWithInitButNoConst
 	public var b = 2;
 }
 
-private class ClassWithInitAndConstructorChild extends ClassWithInitButNoConstructor {
-	public var b = 2;
-	public function new() {
-		super();
-	}
-}
+//private class ClassWithInitAndConstructorChild extends ClassWithInitButNoConstructor {
+	//public var b = 2;
+	//public function new() {
+		//super();
+	//}
+//}
 
 private class ClassWithConstructor {
 	public var a = 1;
@@ -50,9 +50,9 @@ class Issue3596 extends Test {
 		t(unit.TestType.typeError(new ClassWithInitButNoConstructor()));
 		t(unit.TestType.typeError(new ClassWithInitButNoConstructorChild()));
 
-		var c = new ClassWithInitAndConstructorChild();
-		eq(1, c.a);
-		eq(2, c.b);
+		//var c = new ClassWithInitAndConstructorChild();
+		//eq(1, c.a);
+		//eq(2, c.b);
 
 		var c = new ClassWithConstructor();
 		eq(2, c.a);

+ 1 - 0
typer.ml

@@ -3800,6 +3800,7 @@ and type_call ctx e el (with_type:with_type) p =
 		| None -> error "Current class does not have a super" p
 		| Some (c,params) ->
 			let ct, f = get_constructor ctx c params p in
+			if (Meta.has Meta.CompilerGenerated f.cf_meta) then display_error ctx (s_type_path c.cl_path ^ " does not have a constructor") p;
 			let el = (match follow ct with
 			| TFun (args,r) ->
 				let el,_,_ = unify_field_call ctx (FInstance(c,params,f)) el args r p false in