groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cchamp...@apache.org
Subject [1/5] incubator-groovy git commit: GROOVY-7610 Null safe is calls throw VerifyError when used as condition with CompileStatic * Null safe .is method call expressions were being transformed to CompareIdentityExpressions
Date Wed, 07 Oct 2015 19:16:54 GMT
Repository: incubator-groovy
Updated Branches:
  refs/heads/master d3bc07e5c -> baba6dfdf


GROOVY-7610 Null safe is calls throw VerifyError when used as condition with CompileStatic
* Null safe .is method call expressions were being transformed to CompareIdentityExpressions

Closes #123


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

Branch: refs/heads/master
Commit: 0a54e553b12cff530d6910d918e7c17f0c6f3173
Parents: d3bc07e
Author: Shil S <shil.sinha@gmail.com>
Authored: Tue Sep 29 00:53:21 2015 -0400
Committer: Cedric Champeau <cchampeau@apache.org>
Committed: Wed Oct 7 21:06:58 2015 +0200

----------------------------------------------------------------------
 .../MethodCallExpressionTransformer.java           |  3 ++-
 .../classgen/asm/sc/BugsStaticCompileTest.groovy   | 17 +++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/0a54e553/src/main/org/codehaus/groovy/transform/sc/transformers/MethodCallExpressionTransformer.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/sc/transformers/MethodCallExpressionTransformer.java
b/src/main/org/codehaus/groovy/transform/sc/transformers/MethodCallExpressionTransformer.java
index e6cae53..982865f 100644
--- a/src/main/org/codehaus/groovy/transform/sc/transformers/MethodCallExpressionTransformer.java
+++ b/src/main/org/codehaus/groovy/transform/sc/transformers/MethodCallExpressionTransformer.java
@@ -170,9 +170,10 @@ public class MethodCallExpressionTransformer {
      * @return null if the method call is not DGM#is, or {@link CompareIdentityExpression}
      */
     private static Expression tryTransformIsToCompareIdentity(MethodCallExpression call)
{
+        if (call.isSafe()) return null;
         MethodNode methodTarget = call.getMethodTarget();
         if (methodTarget instanceof ExtensionMethodNode && "is".equals(methodTarget.getName())
&& methodTarget.getParameters().length==1) {
-           methodTarget = ((ExtensionMethodNode) methodTarget).getExtensionMethodNode();
+            methodTarget = ((ExtensionMethodNode) methodTarget).getExtensionMethodNode();
             ClassNode owner = methodTarget.getDeclaringClass();
             if (DGM_CLASSNODE.equals(owner)) {
                 Expression args = call.getArguments();

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/0a54e553/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
index b83ecab..922448e 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
@@ -1393,5 +1393,22 @@ println someInt
             assert foo.name == 'fluent'
         '''
     }
+
+    // GROOVY-7610
+    void testNullSafeIsCallConditionShouldNotThrowVerifyError() {
+        assertScript '''
+            class A {
+                void ifCondition(Object x, Object y) {
+                    if (x?.is(y))
+                        return
+                }
+
+                void ternaryCondition(Object x, Object y) {
+                    x?.is(y) ? 'foo' : 'bar'
+                }
+            }
+            new A()
+        '''
+    }
 }
 


Mime
View raw message