Browse Source

[typer] type operator lhs against expected type (#11428)

see #10981
Simon Krajewski 1 year ago
parent
commit
af369a7765
2 changed files with 19 additions and 0 deletions
  1. 4 0
      src/typing/operators.ml
  2. 15 0
      tests/unit/src/unit/issues/Issue10981.hx

+ 4 - 0
src/typing/operators.ml

@@ -630,6 +630,10 @@ let type_non_assign_op ctx op e1 e2 is_assign_op abstract_overload_only with_typ
 			WithType.value
 	in
 	let e1 = type_expr ctx e1 wt in
+	let e1 = match wt with
+		| WithType.WithType(t,_) -> AbstractCast.cast_or_unify ctx t e1 e1.epos
+		| _ -> e1
+	in
 	let result = if abstract_overload_only then begin
 		let e2 = type_binop_rhs ctx op e1 e2 is_assign_op with_type p in
 		try_abstract_binop_overloads ctx op e1 e2 is_assign_op p

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

@@ -0,0 +1,15 @@
+package unit.issues;
+
+import haxe.EnumFlags;
+
+private enum E {
+	A;
+	B;
+}
+
+class Issue10981 extends Test {
+	function test() {
+		var flags:EnumFlags<E> = A | B;
+		eq(3, flags.toInt());
+	}
+}