Procházet zdrojové kódy

deal with KAbstract + KFloat/KInt (closes #4122)

Simon Krajewski před 10 roky
rodič
revize
d40ed7b13f
2 změnil soubory, kde provedl 36 přidání a 0 odebrání
  1. 24 0
      tests/unit/src/unit/issues/Issue4122.hx
  2. 12 0
      typer.ml

+ 24 - 0
tests/unit/src/unit/issues/Issue4122.hx

@@ -0,0 +1,24 @@
+package unit.issues;
+
+@:enum
+private abstract Test2(Int) to Int {
+	var PROP = 123;
+}
+
+private abstract Test3(Int) {
+	static public var PROP = 123;
+}
+
+class Issue4122 extends Test {
+	function test() {
+		eq(130, Test2.PROP + 7);
+		unit.TestType.typedAs(Test2.PROP + 7, 7);
+		feq(130.5, Test2.PROP + 7.5);
+		unit.TestType.typedAs(Test2.PROP + 7.5, 7.5);
+
+		eq(130, Test3.PROP + 7);
+		unit.TestType.typedAs(Test3.PROP + 7, 7);
+		feq(130.5, Test3.PROP + 7.5);
+		unit.TestType.typedAs(Test3.PROP + 7.5, 7.5);
+	}
+}

+ 12 - 0
typer.ml

@@ -2085,6 +2085,18 @@ and type_binop2 ctx op (e1 : texpr) (e2 : Ast.expr) is_assign_op wt p =
 		| KUnk, KParam t ->
 			unify ctx e1.etype tfloat e1.epos;
 			tfloat
+		| KAbstract _,KFloat ->
+			unify ctx e1.etype tfloat e1.epos;
+			tfloat
+		| KFloat, KAbstract _ ->
+			unify ctx e2.etype tfloat e2.epos;
+			tfloat
+		| KAbstract _,KInt ->
+			unify ctx e1.etype ctx.t.tint e1.epos;
+			ctx.t.tint
+		| KInt, KAbstract _ ->
+			unify ctx e2.etype ctx.t.tint e2.epos;
+			ctx.t.tint
 		| KAbstract _,_
 		| _,KAbstract _
 		| KParam _, _