Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X e0026bb77 -> 1b7ba8650


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/1b7ba865
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/1b7ba865
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/1b7ba865

Branch: refs/heads/GROOVY_2_6_X
Commit: 1b7ba8650351010491633143b71bde85a36b0622
Parents: e0026bb
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:32:03 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/1b7ba865/src/main/java/org/codehaus/groovy/classgen/asm/BinaryBooleanExpressionHelper.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/codehaus/groovy/classgen/asm/BinaryBooleanExpressionHelper.java
 
b/src/main/java/org/codehaus/groovy/classgen/asm/BinaryBooleanExpressionHelper.java
index 18e3169..def371b 100644
--- 
a/src/main/java/org/codehaus/groovy/classgen/asm/BinaryBooleanExpressionHelper.java
+++ 
b/src/main/java/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 {
 
@@ -49,6 +51,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");
     }
@@ -58,10 +62,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/1b7ba865/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