Browse Source

[analyzer] fix TEnumIndex and TEnumParameter side-effect handling

closes #10032
Simon Krajewski 4 years ago
parent
commit
acfea7f309
2 changed files with 23 additions and 2 deletions
  1. 2 2
      src/optimization/analyzerTexpr.ml
  2. 21 0
      tests/unit/src/unit/issues/Issue10032.hx

+ 2 - 2
src/optimization/analyzerTexpr.ml

@@ -538,7 +538,7 @@ module Fusion = struct
 			| {eexpr = TField (_,fa)} as e1 :: el when PurityState.is_explicitly_impure fa ->
 				block_element (e1 :: acc) el
 			(* no-side-effect *)
-			| {eexpr = TEnumParameter _ | TEnumIndex _ | TFunction _ | TConst _ | TTypeExpr _} :: el ->
+			| {eexpr = TFunction _ | TConst _ | TTypeExpr _} :: el ->
 				block_element acc el
 			| {eexpr = TMeta((Meta.Pure,_,_),_)} :: el ->
 				block_element acc el
@@ -561,7 +561,7 @@ module Fusion = struct
 				| None -> block_element (e :: acc) el
 				end
 			(* no-side-effect composites *)
-			| {eexpr = TParenthesis e1 | TMeta(_,e1) | TCast(e1,None) | TField(e1,_) | TUnop(_,_,e1)} :: el ->
+			| {eexpr = TParenthesis e1 | TMeta(_,e1) | TCast(e1,None) | TField(e1,_) | TUnop(_,_,e1) | TEnumIndex e1 | TEnumParameter(e1,_,_)} :: el ->
 				block_element acc (e1 :: el)
 			| {eexpr = TArray(e1,e2) | TBinop(_,e1,e2)} :: el ->
 				block_element acc (e1 :: e2 :: el)

+ 21 - 0
tests/unit/src/unit/issues/Issue10032.hx

@@ -0,0 +1,21 @@
+package unit.issues;
+
+private enum Foo {
+	A;
+	B;
+}
+
+class Issue10032 extends Test {
+	static var a:Foo = A;
+
+	static function onChange(v:Foo)
+		switch a = v {
+			case A: // Commenting out this line fixes the issue.
+			case _:
+		}
+
+	function test() {
+		onChange(B);
+		t(a == B);
+	}
+}