Jelajahi Sumber

allow extra fields on structure declarations if they are quoted (closes #3547)

Simon Krajewski 10 tahun lalu
induk
melakukan
605addd07d
3 mengubah file dengan 20 tambahan dan 2 penghapusan
  1. 2 1
      tests/unit/src/unit/TestType.hx
  2. 16 0
      tests/unit/src/unit/issues/Issue3547.hx
  3. 2 1
      typer.ml

+ 2 - 1
tests/unit/src/unit/TestType.hx

@@ -313,7 +313,8 @@ class TestType extends Test {
 		t(typeError( { var b: { v:Int } = { v:0, v:2 }; } ));
 		t(typeError( { var b: { v:Int, w:String } = { v:0 }; } ));
 		typedAs({ v: 0.2, " foo":2 }, a);
-		t(typeError(a = { v:0, " foo":2 } ));
+		// this is allowed now (https://github.com/HaxeFoundation/haxe/issues/3547)
+		//t(typeError(a = { v:0, " foo":2 } ));
 		f(typeError(func("foo", { x:1.2, y:2 } )));
 		f(typeError(func("foo", { w:1.2, h:2 } )));
 	}

+ 16 - 0
tests/unit/src/unit/issues/Issue3547.hx

@@ -0,0 +1,16 @@
+package unit.issues;
+
+private typedef Option = {
+	?foo: Int,
+	?bar: Int,
+}
+
+class Issue3547 extends Test {
+	function test() {
+		var o = {foo:12, "x-bar":13};
+		assign(o);
+		assign({foo:12, "x-bar":13});
+	}
+
+	static function assign(o:Option) { }
+}

+ 2 - 1
typer.ml

@@ -2871,7 +2871,8 @@ and type_expr ctx (e,p) (with_type:with_type) =
 					let e = Codegen.AbstractCast.cast_or_unify ctx t e p in
 					(try type_eq EqStrict e.etype t; e with Unify_error _ -> mk (TCast (e,None)) t e.epos)
 				with Not_found ->
-					extra_fields := n :: !extra_fields;
+					if add then
+						extra_fields := n :: !extra_fields;
 					type_expr ctx e Value
 				in
 				if add then begin