Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X a4542b9ef -> 064e8653c


GROOVY-8539: Groovy fails to compile assignment operators on boolean array 
(closes #683)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/064e8653
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/064e8653
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/064e8653

Branch: refs/heads/GROOVY_2_4_X
Commit: 064e8653cdf0127660c6ee6bd6e5d8b646359d92
Parents: a4542b9
Author: Paul King <pa...@asert.com.au>
Authored: Wed Apr 11 16:12:59 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Fri Apr 13 03:35:25 2018 +1000

----------------------------------------------------------------------
 .../classgen/asm/BinaryBooleanExpressionHelper.java    | 10 +++++-----
 src/test/groovy/operator/BooleanOperationsTest.groovy  | 13 +++++++++++++
 2 files changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/064e8653/src/main/org/codehaus/groovy/classgen/asm/BinaryBooleanExpressionHelper.java
----------------------------------------------------------------------
diff --git 
a/src/main/org/codehaus/groovy/classgen/asm/BinaryBooleanExpressionHelper.java 
b/src/main/org/codehaus/groovy/classgen/asm/BinaryBooleanExpressionHelper.java
index 11b84ab..f8d38d6 100644
--- 
a/src/main/org/codehaus/groovy/classgen/asm/BinaryBooleanExpressionHelper.java
+++ 
b/src/main/org/codehaus/groovy/classgen/asm/BinaryBooleanExpressionHelper.java
@@ -24,8 +24,10 @@ import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.runtime.BytecodeInterface8;
 import org.objectweb.asm.MethodVisitor;
 
+import static org.codehaus.groovy.syntax.Types.PLUS;
+
 /**
- * @author <a href="mailto:blackd...@gmx.org";>Jochen "blackdrag" Theodorou</a>
+ * Binary write operations specialised for Booleans
  */
 public class BinaryBooleanExpressionHelper extends BinaryIntExpressionHelper {
 
@@ -59,6 +61,8 @@ public class BinaryBooleanExpressionHelper extends 
BinaryIntExpressionHelper {
     
     @Override
     protected boolean writeStdOperators(int type, boolean simulate) {
+        type = type - PLUS;
+        if (type < 0 || type > 5 || type == 3 /*DIV*/) return false;
         if (simulate) return false;
         throw new GroovyBugError("should not reach here");
     }
@@ -68,10 +72,6 @@ public class BinaryBooleanExpressionHelper extends 
BinaryIntExpressionHelper {
         throw new GroovyBugError("should not reach here");
     }
 
-    protected int getBitwiseOperationBytecode(int type) {
-        return -1;
-    }
-    
     protected ClassNode getNormalOpResultType() {
         return ClassHelper.boolean_TYPE;
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/064e8653/src/test/groovy/operator/BooleanOperationsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/operator/BooleanOperationsTest.groovy 
b/src/test/groovy/operator/BooleanOperationsTest.groovy
index e864939..d062e73 100644
--- a/src/test/groovy/operator/BooleanOperationsTest.groovy
+++ b/src/test/groovy/operator/BooleanOperationsTest.groovy
@@ -141,4 +141,17 @@ class BooleanOperationsTest extends GroovyTestCase {
         assert z == false
     }
 
+    void testBooleanAssignArrayOps() {
+        boolean[] b = [true]
+        b[0] &= false
+        assert b == [false]
+        b[0] ^= true
+        assert b == [true]
+        b[0] ^= true
+        assert b == [false]
+        b[0] |= true
+        assert b == [true]
+        b[0] |= false
+        assert b == [true]
+    }
 }

Reply via email to