GROOVY-8380: Regression in 2.4.13 (snapshot) with and/or/xor and @CS

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

Branch: refs/heads/master
Commit: afe5851affd5756fb6065560909e498c07905660
Parents: 4425a70
Author: paulk <[email protected]>
Authored: Fri Nov 17 20:32:34 2017 +1000
Committer: paulk <[email protected]>
Committed: Fri Nov 17 20:33:46 2017 +1000

----------------------------------------------------------------------
 .../asm/sc/StaticTypesCallSiteWriter.java       |  3 ++-
 .../stc/StaticTypeCheckingVisitor.java          |  6 +++---
 .../groovy/transform/stc/MiscSTCTest.groovy     | 20 ++++++++++++++++++++
 3 files changed, 25 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/afe5851a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
----------------------------------------------------------------------
diff --git 
a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java 
b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
index 2eaa934..9968ef6 100644
--- 
a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
+++ 
b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
@@ -654,7 +654,8 @@ public class StaticTypesCallSiteWriter extends 
CallSiteWriter implements Opcodes
             } else if ("power".equals(message)) {
                 writePowerCall(receiver, arguments, rType, aType);
                 return true;
-            } else if ("mod".equals(message) || "leftShift".equals(message) || 
"rightShift".equals(message) || "rightShiftUnsigned".equals(message)) {
+            } else if ("mod".equals(message) || "leftShift".equals(message) || 
"rightShift".equals(message) || "rightShiftUnsigned".equals(message)
+                    || "and".equals(message) || "or".equals(message) || 
"xor".equals(message)) {
                 writeOperatorCall(receiver, arguments, message);
                 return true;
             }

http://git-wip-us.apache.org/repos/asf/groovy/blob/afe5851a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git 
a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java 
b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index e7133bd..8efe2b6 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3659,9 +3659,9 @@ public class StaticTypeCheckingVisitor extends 
ClassCodeVisitorSupport {
             } else if (isPowerOperator(op)) {
                 return Number_TYPE;
             } else if (isBitOperator(op)) {
-                if (isIntCategory(leftRedirect) && 
isIntCategory(rightRedirect)) return int_TYPE;
-                if (isLongCategory(leftRedirect) && 
isLongCategory(rightRedirect)) return long_TYPE;
-                if (isBigIntCategory(leftRedirect) && 
isBigIntCategory(rightRedirect)) return BigInteger_TYPE;
+                if (isIntCategory(getUnwrapper(leftRedirect)) && 
isIntCategory(getUnwrapper(rightRedirect))) return int_TYPE;
+                if (isLongCategory(getUnwrapper(leftRedirect)) && 
isLongCategory(getUnwrapper(rightRedirect))) return long_TYPE;
+                if (isBigIntCategory(getUnwrapper(leftRedirect)) && 
isBigIntCategory(getUnwrapper(rightRedirect))) return BigInteger_TYPE;
             } else if (isCompareToBoolean(op) || op == COMPARE_EQUAL || op == 
COMPARE_NOT_EQUAL) {
                 return boolean_TYPE;
             }

http://git-wip-us.apache.org/repos/asf/groovy/blob/afe5851a/src/test/groovy/transform/stc/MiscSTCTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/MiscSTCTest.groovy 
b/src/test/groovy/transform/stc/MiscSTCTest.groovy
index fd132e3..0b786d8 100644
--- a/src/test/groovy/transform/stc/MiscSTCTest.groovy
+++ b/src/test/groovy/transform/stc/MiscSTCTest.groovy
@@ -389,4 +389,24 @@ class MiscSTCTest extends StaticTypeCheckingTestCase {
         ''', 'Cannot find matching method Foo#newInstance2(CustomNumber)'
     }
 
+    // GROOVY-8380
+    void testBitOperatorsWithNumbers() {
+        assertScript '''
+            def method() {
+                Long wl = 2L
+                long pl = 3L
+                assert new Long(wl & 3L) == 2
+                assert new Long(pl & pl) == 3
+                assert new Long(6L & 3L) == 2
+                assert new Long(-2L & 3L) == 2
+                Integer wi = 2
+                int pi = 2
+                assert new Integer(wi & 34) == 2
+                assert new Integer(pi & pi) == 2
+                assert new Integer(6 & 3) == 2
+                assert new Integer(-2 & 3) == 2
+            }
+            method()
+        '''
+    }
 }

Reply via email to