groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [1/2] groovy git commit: GROOVY-8203: Add @Newify will cause ?. operator NPE (closes #550)
Date Fri, 26 May 2017 02:07:45 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 0ad49d6ab -> e33a4e0c6


GROOVY-8203: Add @Newify will cause ?. operator NPE (closes #550)


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 506683d0095558822da4375a3922b26862b1fe3d
Parents: 0ad49d6
Author: paulk <paulk@asert.com.au>
Authored: Thu May 25 17:26:54 2017 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Fri May 26 12:06:54 2017 +1000

----------------------------------------------------------------------
 .../groovy/transform/NewifyASTTransformation.java |  5 ++---
 .../groovy/transform/NewifyTransformTest.groovy   | 18 ++++++++++++++++--
 2 files changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/506683d0/src/main/org/codehaus/groovy/transform/NewifyASTTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/NewifyASTTransformation.java b/src/main/org/codehaus/groovy/transform/NewifyASTTransformation.java
index 5e5f9db..4044178 100644
--- a/src/main/org/codehaus/groovy/transform/NewifyASTTransformation.java
+++ b/src/main/org/codehaus/groovy/transform/NewifyASTTransformation.java
@@ -49,9 +49,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.callX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.classX;
 
 /**
- * Handles generation of code for the @Newify annotation.
- *
- * @author Paul King
+ * Handles generation of code for the {@code @Newify} AST transform.
  */
 @GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
 public class NewifyASTTransformation extends ClassCodeExpressionTransformer implements ASTTransformation
{
@@ -167,6 +165,7 @@ public class NewifyASTTransformation extends ClassCodeExpressionTransformer
impl
             Expression object = transform(mce.getObjectExpression());
             MethodCallExpression transformed = callX(object, method, args);
             transformed.setImplicitThis(mce.isImplicitThis());
+            transformed.setSafe(mce.isSafe());
             transformed.setSourcePosition(mce);
             return transformed;
         } else if (expr instanceof ClosureExpression) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/506683d0/src/test/org/codehaus/groovy/transform/NewifyTransformTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/transform/NewifyTransformTest.groovy b/src/test/org/codehaus/groovy/transform/NewifyTransformTest.groovy
index b6d0255..e3e9890 100644
--- a/src/test/org/codehaus/groovy/transform/NewifyTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/NewifyTransformTest.groovy
@@ -19,7 +19,7 @@
 package org.codehaus.groovy.transform
 
 /**
- * @author Paul King
+ * Tests for the {@code @Newify} AST transform.
  */
 class NewifyTransformTest extends GroovyShellTestCase {
 
@@ -158,7 +158,6 @@ class NewifyTransformTest extends GroovyShellTestCase {
         assert test == 'ABC'
     }
 
-
     void testNewifyClosureCompileStatic_Groovy7758() {
         assertScript '''
             class A {
@@ -175,4 +174,19 @@ class NewifyTransformTest extends GroovyShellTestCase {
             assert test(new A()) == 'abc'
         '''
     }
+
+    void testNewifyTransformPreservesSafeMethodCall_Groovy8203() {
+        assertScript '''
+            @Newify(A)
+            class Z {
+                def foo() {
+                    def a
+                    a?.get('b')
+                }
+                class A {}
+            }
+
+            assert !new Z().foo()
+        '''
+    }
 }
\ No newline at end of file


Mime
View raw message