Browse Source

fix forced constructor creation (closes #4557)

Instead of not generating constructor for classes that extend a forced constructor class, we create a constructor but retain the `@:compilerGenerated` metadata.
Simon Krajewski 9 năm trước cách đây
mục cha
commit
4560d28610
2 tập tin đã thay đổi với 27 bổ sung2 xóa
  1. 25 0
      tests/unit/src/unit/issues/Issue4557.hx
  2. 2 2
      typeload.ml

+ 25 - 0
tests/unit/src/unit/issues/Issue4557.hx

@@ -0,0 +1,25 @@
+package unit.issues;
+
+private class Ghost {
+	public var value:String;
+	public function new(value) {
+		this.value = value;
+	}
+}
+
+private class A {
+	public var ghost = new Ghost("booh!");
+}
+
+private class B extends A { }
+
+private class C extends B {
+	public function new() { }
+}
+
+class Issue4557 extends Test {
+	function test() {
+        var c = new C();
+        eq("booh!", c.ghost.value);
+	}
+}

+ 2 - 2
typeload.ml

@@ -1270,11 +1270,11 @@ let check_strict_meta ctx metas =
 
 let rec add_constructor ctx c force_constructor p =
 	match c.cl_constructor, c.cl_super with
-	| None, Some ({ cl_constructor = Some cfsup } as csup,cparams) when not c.cl_extern && not (Meta.has Meta.CompilerGenerated cfsup.cf_meta) ->
+	| None, Some ({ cl_constructor = Some cfsup } as csup,cparams) when not c.cl_extern ->
 		let cf = {
 			cfsup with
 			cf_pos = p;
-			cf_meta = [];
+			cf_meta = List.filter (fun (m,_,_) -> m = Meta.CompilerGenerated) cfsup.cf_meta;
 			cf_doc = None;
 			cf_expr = None;
 		} in