You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by sh...@apache.org on 2016/07/07 02:54:55 UTC
groovy git commit: GROOVY-7870: BinaryExpressionTransformer: Set line
numbers on transformed binary expressions (closes #362)
Repository: groovy
Updated Branches:
refs/heads/master abec2cf90 -> e16227821
GROOVY-7870: BinaryExpressionTransformer: Set line numbers on transformed binary expressions (closes #362)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/e1622782
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/e1622782
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/e1622782
Branch: refs/heads/master
Commit: e16227821c48980aec3ed83cdc3791499ce6ef78
Parents: abec2cf
Author: Shil Sinha <sh...@apache.org>
Authored: Sat Jul 2 11:29:21 2016 -0400
Committer: Shil Sinha <sh...@apache.org>
Committed: Wed Jul 6 19:24:45 2016 -0700
----------------------------------------------------------------------
.../BinaryExpressionTransformer.java | 2 +
.../classgen/asm/sc/bugs/Groovy7870Bug.groovy | 141 +++++++++++++++++++
2 files changed, 143 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/e1622782/src/main/org/codehaus/groovy/transform/sc/transformers/BinaryExpressionTransformer.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/sc/transformers/BinaryExpressionTransformer.java b/src/main/org/codehaus/groovy/transform/sc/transformers/BinaryExpressionTransformer.java
index 3460292..d726ee8 100644
--- a/src/main/org/codehaus/groovy/transform/sc/transformers/BinaryExpressionTransformer.java
+++ b/src/main/org/codehaus/groovy/transform/sc/transformers/BinaryExpressionTransformer.java
@@ -137,6 +137,7 @@ public class BinaryExpressionTransformer {
MethodCallExpression call = new MethodCallExpression(left, "compareTo", new ArgumentListExpression(right));
call.setImplicitThis(false);
call.setMethodTarget(COMPARE_TO_METHOD);
+ call.setSourcePosition(bin);
CompareIdentityExpression compareIdentity = new CompareIdentityExpression(
left, right
@@ -192,6 +193,7 @@ public class BinaryExpressionTransformer {
call.setMethodTarget(adapter);
call.setImplicitThis(false);
}
+ call.setSourcePosition(bin);
if (!isAssignment) return call;
// case of +=, -=, /=, ...
// the method represents the operation type only, and we must add an assignment
http://git-wip-us.apache.org/repos/asf/groovy/blob/e1622782/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7870Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7870Bug.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7870Bug.groovy
new file mode 100644
index 0000000..6bd9ca4
--- /dev/null
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7870Bug.groovy
@@ -0,0 +1,141 @@
+/*
+ * 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 org.codehaus.groovy.classgen.asm.sc.bugs
+
+import groovy.transform.stc.StaticTypeCheckingTestCase
+import org.codehaus.groovy.classgen.asm.sc.StaticCompilationTestSupport
+
+class Groovy7870Bug extends StaticTypeCheckingTestCase implements StaticCompilationTestSupport {
+
+ void testLineNumberOnImplicitReturnsWithLeftShift() {
+ assertScript '''
+ def test() {
+ def thrower = new org.codehaus.groovy.classgen.asm.sc.bugs.Groovy7870Bug.Thrower()
+ thrower << null
+ }
+ try {
+ test()
+ } catch (org.codehaus.groovy.classgen.asm.sc.bugs.Groovy7870Bug.DummyException e) {
+ def scriptTraceElement = e.stackTrace.find { it.className.startsWith(GroovyTestCase.TEST_SCRIPT_NAME_PREFIX) }
+ assert 4 == scriptTraceElement.lineNumber
+ }
+ '''
+ }
+
+ void testLineNumberOnImplicitReturnsWithRightShift() {
+ assertScript '''
+ def test() {
+ def thrower = new org.codehaus.groovy.classgen.asm.sc.bugs.Groovy7870Bug.Thrower()
+ thrower >> null
+ }
+ try {
+ test()
+ } catch (org.codehaus.groovy.classgen.asm.sc.bugs.Groovy7870Bug.DummyException e) {
+ def scriptTraceElement = e.stackTrace.find { it.className.startsWith(GroovyTestCase.TEST_SCRIPT_NAME_PREFIX) }
+ assert 4 == scriptTraceElement.lineNumber
+ }
+ '''
+ }
+
+ void testLineNumberOnImplicitReturnsWithRightShiftUnsigned() {
+ assertScript '''
+ def test() {
+ def thrower = new org.codehaus.groovy.classgen.asm.sc.bugs.Groovy7870Bug.Thrower()
+ thrower >>> null
+ }
+ try {
+ test()
+ } catch (org.codehaus.groovy.classgen.asm.sc.bugs.Groovy7870Bug.DummyException e) {
+ def scriptTraceElement = e.stackTrace.find { it.className.startsWith(GroovyTestCase.TEST_SCRIPT_NAME_PREFIX) }
+ assert 4 == scriptTraceElement.lineNumber
+ }
+ '''
+ }
+
+ void testLineNumberOnImplicitReturnsWithCompareTo() {
+ assertScript '''
+ def test(org.codehaus.groovy.classgen.asm.sc.bugs.Groovy7870Bug.Thrower o) {
+ def thrower = new org.codehaus.groovy.classgen.asm.sc.bugs.Groovy7870Bug.Thrower()
+ thrower <=> o
+ }
+ try {
+ test(null)
+ } catch (org.codehaus.groovy.classgen.asm.sc.bugs.Groovy7870Bug.DummyException e) {
+ def scriptTraceElement = e.stackTrace.find { it.className.startsWith(GroovyTestCase.TEST_SCRIPT_NAME_PREFIX) }
+ assert 4 == scriptTraceElement.lineNumber
+ }
+ '''
+ }
+
+ void testLineNumberOnImplicitReturnsWithIn() {
+ assertScript '''
+ def test() {
+ def thrower = new org.codehaus.groovy.classgen.asm.sc.bugs.Groovy7870Bug.Thrower()
+ 'abc' in thrower
+ }
+ try {
+ test()
+ } catch (org.codehaus.groovy.classgen.asm.sc.bugs.Groovy7870Bug.DummyException e) {
+ def scriptTraceElement = e.stackTrace.find { it.className.startsWith(GroovyTestCase.TEST_SCRIPT_NAME_PREFIX) }
+ assert 4 == scriptTraceElement.lineNumber
+ }
+ '''
+ }
+
+ void testLineNumberOnImplicitReturnsWithEquals() {
+ assertScript '''
+ def test(org.codehaus.groovy.classgen.asm.sc.bugs.Groovy7870Bug.Thrower o) {
+ def thrower = new org.codehaus.groovy.classgen.asm.sc.bugs.Groovy7870Bug.Thrower()
+ thrower == o
+ }
+ try {
+ test(null)
+ } catch (org.codehaus.groovy.classgen.asm.sc.bugs.Groovy7870Bug.DummyException e) {
+ def scriptTraceElement = e.stackTrace.find { it.className.startsWith(GroovyTestCase.TEST_SCRIPT_NAME_PREFIX) }
+ assert 4 == scriptTraceElement.lineNumber
+ }
+ '''
+ }
+
+ static class Thrower implements Comparable<Thrower> {
+ @Override
+ int compareTo(Thrower o) {
+ throw new DummyException()
+ }
+
+ boolean isCase(Object o) {
+ throw new DummyException()
+ }
+
+ def rightShiftUnsigned(Object o) {
+ throw new DummyException()
+ }
+
+
+ def rightShift(Object o) {
+ throw new DummyException()
+ }
+
+ def leftShift(Object o) {
+ throw new DummyException()
+ }
+ }
+
+ static class DummyException extends Exception {}
+}