You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2016/08/09 07:55:02 UTC
[2/2] groovy git commit: GROOVY-7542: CompileStatic class generation
bug "register with message: rightShiftUnsigned and arguments X" (testcase
plus rightShift/leftShift - closes #85)
GROOVY-7542: CompileStatic class generation bug "register with message: rightShiftUnsigned and arguments X" (testcase plus rightShift/leftShift - closes #85)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/a1eb2ae5
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/a1eb2ae5
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/a1eb2ae5
Branch: refs/heads/master
Commit: a1eb2ae588a46a69e51b27bfc1c926682ee00fdd
Parents: cba9b42
Author: paulk <pa...@asert.com.au>
Authored: Tue Aug 9 17:54:41 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Tue Aug 9 17:54:41 2016 +1000
----------------------------------------------------------------------
.../asm/sc/StaticTypesCallSiteWriter.java | 25 ++++-------------
.../groovy/transform/stc/Groovy7542Bug.groovy | 28 ++++++++++++++++++++
2 files changed, 33 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/a1eb2ae5/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 79dea7d..dd5a913 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
@@ -646,13 +646,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)) {
- writeModCall(receiver, arguments, rType, aType);
- return true;
- }
- else if("rightShiftUnsigned".equals(message))
- {
- writeShiftOperatorCall(receiver, arguments, rType, aType);
+ } else if ("mod".equals(message) || "leftShift".equals(message) || "rightShift".equals(message) || "rightShiftUnsigned".equals(message)) {
+ writeOperatorCall(receiver, arguments, message);
return true;
}
} else if (STRING_TYPE.equals(rType) && "plus".equals(message)) {
@@ -745,23 +740,13 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
operandStack.replace(rType.getComponentType(), m2-m1);
}
- private void writeModCall(Expression receiver, Expression arguments, ClassNode rType, ClassNode aType) {
- prepareSiteAndReceiver(receiver, "mod", false, controller.getCompileStack().isLHS());
- controller.getOperandStack().doGroovyCast(Number_TYPE);
- visitBoxedArgument(arguments);
- controller.getOperandStack().doGroovyCast(Number_TYPE);
- MethodVisitor mv = controller.getMethodVisitor();
- mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/typehandling/NumberMath", "mod", "(Ljava/lang/Number;Ljava/lang/Number;)Ljava/lang/Number;", false);
- controller.getOperandStack().replace(Number_TYPE, 2);
- }
-
- private void writeShiftOperatorCall(Expression receiver, Expression arguments, ClassNode rType, ClassNode aType) {
- prepareSiteAndReceiver(receiver, "rightShiftUnsigned", false, controller.getCompileStack().isLHS());
+ private void writeOperatorCall(Expression receiver, Expression arguments, String operator) {
+ prepareSiteAndReceiver(receiver, operator, false, controller.getCompileStack().isLHS());
controller.getOperandStack().doGroovyCast(Number_TYPE);
visitBoxedArgument(arguments);
controller.getOperandStack().doGroovyCast(Number_TYPE);
MethodVisitor mv = controller.getMethodVisitor();
- mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/typehandling/NumberMath", "rightShiftUnsigned", "(Ljava/lang/Number;Ljava/lang/Number;)Ljava/lang/Number;", false);
+ mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/typehandling/NumberMath", operator, "(Ljava/lang/Number;Ljava/lang/Number;)Ljava/lang/Number;", false);
controller.getOperandStack().replace(Number_TYPE, 2);
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/a1eb2ae5/src/test/groovy/transform/stc/Groovy7542Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/Groovy7542Bug.groovy b/src/test/groovy/transform/stc/Groovy7542Bug.groovy
new file mode 100644
index 0000000..18a5740
--- /dev/null
+++ b/src/test/groovy/transform/stc/Groovy7542Bug.groovy
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package groovy.transform.stc
+
+class Groovy7542Bug extends StaticTypeCheckingTestCase {
+ void testShiftOperators() {
+ assert [20].collect { it >> 2 } == [5]
+ assert [20].collect { it >>> 2 } == [5]
+ assert [20].collect { it << 2 } == [80]
+ }
+}