Browse Source

use `{}` instead of `null` for creating a fake expression in Context.unify to avoid static target null issues (closes #3365)

Simon Krajewski 11 years ago
parent
commit
34feedf637
2 changed files with 20 additions and 1 deletions
  1. 1 1
      interp.ml
  2. 19 0
      tests/unit/issues/Issue3365.hx

+ 1 - 1
interp.ml

@@ -2345,7 +2345,7 @@ let macro_lib =
 			with Exit -> VNull
 			with Exit -> VNull
 		);
 		);
 		"unify", Fun2 (fun t1 t2 ->
 		"unify", Fun2 (fun t1 t2 ->
-			let e1 = mk (TConst TNull) (decode_type t1) Ast.null_pos in
+			let e1 = mk (TObjectDecl []) (decode_type t1) Ast.null_pos in
 			try ignore(((get_ctx()).curapi.cast_or_unify) (decode_type t2) e1 Ast.null_pos); VBool true
 			try ignore(((get_ctx()).curapi.cast_or_unify) (decode_type t2) e1 Ast.null_pos); VBool true
 			with Typecore.Error (Typecore.Unify _,_) -> VBool false
 			with Typecore.Error (Typecore.Unify _,_) -> VBool false
 		);
 		);

+ 19 - 0
tests/unit/issues/Issue3365.hx

@@ -0,0 +1,19 @@
+package unit.issues;
+
+private abstract IntKey(String) {
+    @:from inline static function fromInt(v:Int):IntKey return cast "";
+}
+
+class Issue3365 extends Test {
+
+	function test() {
+		t(func());
+	}
+
+    static macro function func() {
+        var t1 = haxe.macro.Context.typeof(macro 1);
+        var t2 = haxe.macro.Context.typeof(macro (null : IntKey));
+        var r = haxe.macro.Context.unify(t1, t2);
+		return macro $v{r};
+    }
+}