Browse Source

[analyzer] fix TEnumIndex and TEnumParameter side-effect handling

closes #10032
Aleksandr Kuzmenko 4 years ago
parent
commit
7441e19446
3 changed files with 24 additions and 2 deletions
  1. 1 0
      extra/CHANGES.txt
  2. 2 2
      src/optimization/analyzerTexpr.ml
  3. 21 0
      tests/unit/src/unit/issues/Issue10032.hx

+ 1 - 0
extra/CHANGES.txt

@@ -10,6 +10,7 @@
 
 	all : fixed compiler hanging on `switch` for abstracts with implicit casts involving type parameters and constraints (#10082)
 	all : fixed inlining of `haxe.DynamicAccess.keyValueIterator` (#10118)
+	analyzer : fixed side effect handling for enums (#10032)
 	cpp : fixed handling of `cpp.ConstCharStar` with analyzer enabled (#9733)
 
 2021-02-09 4.2.0:

+ 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);
+	}
+}