Selaa lähdekoodia

[typer] deal with reflexive monomorph binding

closes #9661
Simon Krajewski 5 vuotta sitten
vanhempi
commit
3aec09f522

+ 1 - 1
src/core/tUnification.ml

@@ -151,7 +151,7 @@ module Monomorph = struct
 			constrain_to_type m None t;
 			ignore(close m)
 		| TMono m2 ->
-			begin match m2.tm_type with
+			if m != m2 then begin match m2.tm_type with
 			| None ->
 				List.iter (fun constr -> m2.tm_constraints <- constr :: m2.tm_constraints) m.tm_constraints;
 				do_bind m t;

+ 15 - 0
tests/unit/src/unit/issues/Issue9661.hx

@@ -0,0 +1,15 @@
+package unit.issues;
+import unit.Test;
+import unit.issues.misc.Issue9661Macro;
+
+private typedef Foo = {
+	function make<T>(v:T):Foo;
+}
+
+class Issue9661 extends Test {
+	public function test() {
+		var foo:Foo = {make: null}
+		Issue9661Macro.run(foo.make != null);
+		utest.Assert.pass();
+	}
+}

+ 27 - 0
tests/unit/src/unit/issues/misc/Issue9661Macro.hx

@@ -0,0 +1,27 @@
+package unit.issues.misc;
+
+import haxe.macro.Expr;
+import haxe.macro.Context;
+
+class Issue9661Macro {
+	public macro static function run(e:Expr) {
+		switch e {
+			case {expr: EBinop(op, e1, e2), pos: pos}:
+				switch Context.typeExpr(e) {
+					case t_expr = {expr: TBinop(t_op, t_e1, t_e2)}:
+						var lstored = Context.storeTypedExpr(t_e1);
+						var rstored = Context.storeTypedExpr(t_e2);
+						return macro {
+							var lh = $lstored;
+							var rh = $rstored;
+							${{expr: EBinop(op, macro @:pos(e1.pos) lh, macro @:pos(e2.pos) rh), pos: pos}};
+						}
+					case _:
+						throw 'unreachable';
+				}
+			case _:
+					throw 'unreachable';
+
+		}
+	}
+}