瀏覽代碼

do not use underlying type as expected type for structure declarations (closes #3437)

Simon Krajewski 10 年之前
父節點
當前提交
eef43d666c
共有 2 個文件被更改,包括 34 次插入2 次删除
  1. 31 0
      tests/unit/src/unit/issues/Issue3437.hx
  2. 3 2
      typer.ml

+ 31 - 0
tests/unit/src/unit/issues/Issue3437.hx

@@ -0,0 +1,31 @@
+package unit.issues;
+
+private typedef Struct = {
+	var a: Int;
+}
+
+private typedef OtherStruct = {
+	var b: Int;
+}
+
+private abstract Abstract(Struct) from Struct to Struct {
+
+	public function new(t:Struct) this = t;
+
+	public function getA() {
+		return this.a;
+	}
+
+	@:to public function toOtherStruct():OtherStruct return { b: this.a };
+
+	@:from public static function fromOtherStruct(f:OtherStruct)
+		return new Abstract({ a: f.b });
+}
+
+
+class Issue3437 extends Test {
+	function test() {
+		var x:Abstract = { b: 5 };
+		eq(5, x.getA());
+	}
+}

+ 3 - 2
typer.ml

@@ -2879,11 +2879,12 @@ and type_expr ctx (e,p) (with_type:with_type) =
 		| WithType t | WithTypeResume t ->
 		| WithType t | WithTypeResume t ->
 			(match follow t with
 			(match follow t with
 			| TAnon a when not (PMap.is_empty a.a_fields) -> Some a
 			| TAnon a when not (PMap.is_empty a.a_fields) -> Some a
-			| TAbstract (a,tl) when not (Meta.has Meta.CoreType a.a_meta) && a.a_from <> [] ->
+			(* issues with https://github.com/HaxeFoundation/haxe/issues/3437 *)
+(* 			| TAbstract (a,tl) when not (Meta.has Meta.CoreType a.a_meta) && a.a_from <> [] ->
 				begin match follow (Abstract.get_underlying_type a tl) with
 				begin match follow (Abstract.get_underlying_type a tl) with
 					| TAnon a when not (PMap.is_empty a.a_fields) -> Some a
 					| TAnon a when not (PMap.is_empty a.a_fields) -> Some a
 					| _ -> None
 					| _ -> None
-				end
+				end *)
 			| TDynamic t when (follow t != t_dynamic) ->
 			| TDynamic t when (follow t != t_dynamic) ->
 				dynamic_parameter := Some t;
 				dynamic_parameter := Some t;
 				Some {
 				Some {