You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by cc...@apache.org on 2015/10/07 21:16:54 UTC

[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

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 <sh...@gmail.com>
Authored: Tue Sep 29 00:53:21 2015 -0400
Committer: Cedric Champeau <cc...@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()
+        '''
+    }
 }
 


[3/5] incubator-groovy git commit: GROOVY-7598 Generic types are not checked for return statements (STC)

Posted by cc...@apache.org.
GROOVY-7598 Generic types are not checked for return statements (STC)

Closes #133


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

Branch: refs/heads/master
Commit: 020a9422135ec384384bb018f59cbafc58b6f8c2
Parents: 8a5cd2d
Author: Shil S <sh...@gmail.com>
Authored: Tue Oct 6 12:31:32 2015 -0400
Committer: Cedric Champeau <cc...@apache.org>
Committed: Wed Oct 7 21:12:11 2015 +0200

----------------------------------------------------------------------
 .../stc/StaticTypeCheckingVisitor.java          |  2 ++
 .../groovy/transform/stc/GenericsSTCTest.groovy | 23 +++++++++++++++++++-
 ...ArraysAndCollectionsStaticCompileTest.groovy |  2 +-
 3 files changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/020a9422/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 76bd0d8..1348fb8 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1816,6 +1816,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                         virtualDecl.visit(this);
                         ClassNode newlyInferred = (ClassNode) virtualDecl.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE);
                         if (!missesGenericsTypes(newlyInferred)) type = newlyInferred;
+                    } else {
+                        checkTypeGenerics(enclosingMethod.getReturnType(), inferred, expression);
                     }
                     return type;
                 } else {

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/020a9422/src/test/groovy/transform/stc/GenericsSTCTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index c44ee1a..ec8992e 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -201,7 +201,7 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
         ''', 'Cannot call java.util.LinkedList <String>#<init>(java.util.Collection <java.lang.Object extends java.lang.String>) with arguments [java.util.List <java.lang.Integer>]'
     }
 
-    void testCompatibleGenericAssignmentWithInferrence() {
+    void testCompatibleGenericAssignmentWithInference() {
         shouldFailWithMessages '''
             List<String> elements = ['a','b', 1]
         ''', 'Incompatible generic argument types. Cannot assign java.util.List <java.io.Serializable> to: java.util.List <String>'
@@ -1645,6 +1645,27 @@ assert result == 'ok'
         '''
     }
 
+    void testReturnTypeChecking() {
+        shouldFailWithMessages '''
+            class Foo {
+                List<String> run() {
+                    [11, 12]
+                }
+            }
+        ''', 'Incompatible generic argument types. Cannot assign java.util.List <java.lang.Integer> to: java.util.List <String>'
+    }
+
+    void testBoundedReturnTypeChecking() {
+        assertScript '''
+            class Foo {
+                List<? extends Serializable> run() {
+                    [1, 'a']
+                }
+            }
+            null
+        '''
+    }
+
     static class MyList extends LinkedList<String> {}
 
     public static class ClassA<T> {

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/020a9422/src/test/org/codehaus/groovy/classgen/asm/sc/ArraysAndCollectionsStaticCompileTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/ArraysAndCollectionsStaticCompileTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/ArraysAndCollectionsStaticCompileTest.groovy
index 7bf4f82..af86990 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/ArraysAndCollectionsStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/ArraysAndCollectionsStaticCompileTest.groovy
@@ -64,7 +64,7 @@ class ArraysAndCollectionsStaticCompileTest extends ArraysAndCollectionsSTCTest
     // GROOVY-5988
     void testMapArraySetPropertyAssignment() {
         assertScript '''
-            Map<String, String> props(Object p) {
+            Map<String, Object> props(Object p) {
                 Map<String, Object> props = [:]
 
                 for(String property in p.properties.keySet()){


[2/5] incubator-groovy git commit: GROOVY-7597 Static compiler tries to cast delegate to target type of property accessor * Remove setting of INFERRED_TYPE metadata on synthetic property expression for implicit receiver

Posted by cc...@apache.org.
GROOVY-7597 Static compiler tries to cast delegate to target type of property accessor
* Remove setting of INFERRED_TYPE metadata on synthetic property expression for implicit receiver

Closes #126


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

Branch: refs/heads/master
Commit: 8a5cd2d24fb842c64a9a4c9d6b7310af6876b8ff
Parents: 0a54e55
Author: Shil S <sh...@gmail.com>
Authored: Sun Oct 4 15:11:40 2015 -0400
Committer: Cedric Champeau <cc...@apache.org>
Committed: Wed Oct 7 21:09:40 2015 +0200

----------------------------------------------------------------------
 .../classgen/asm/sc/StaticInvocationWriter.java |  4 ---
 .../asm/sc/DelegatesToStaticCompileTest.groovy  | 33 ++++++++++++++++++++
 2 files changed, 33 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/8a5cd2d2/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
index be657ac..12cca0e 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
@@ -562,7 +562,6 @@ public class StaticInvocationWriter extends InvocationWriter {
 
     boolean tryImplicitReceiver(final Expression origin, final Expression message, final Expression arguments, final MethodCallerMultiAdapter adapter, final boolean safe, final boolean spreadSafe, final boolean implicitThis) {
         Object implicitReceiver = origin.getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER);
-        ClassNode propertyOwnerType = origin.getNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER);
         if (implicitThis && implicitReceiver==null && origin instanceof MethodCallExpression) {
             implicitReceiver = ((MethodCallExpression) origin).getObjectExpression().getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER);
         }
@@ -576,9 +575,6 @@ public class StaticInvocationWriter extends InvocationWriter {
                 pexp = new PropertyExpression(pexp, propertyPath[i]);
             }
             pexp.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, implicitReceiver);
-            if (propertyOwnerType!=null) {
-                pexp.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, propertyOwnerType);
-            }
             origin.removeNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER);
             if (origin instanceof PropertyExpression) {
                 PropertyExpression rewritten = new PropertyExpression(

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/8a5cd2d2/src/test/org/codehaus/groovy/classgen/asm/sc/DelegatesToStaticCompileTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/DelegatesToStaticCompileTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/DelegatesToStaticCompileTest.groovy
index da7a690..e4b2cb2 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/DelegatesToStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/DelegatesToStaticCompileTest.groovy
@@ -80,4 +80,37 @@ class DelegatesToStaticCompileTest extends DelegatesToSTCTest implements StaticC
             assert bytecode.contains('INVOKEVIRTUAL org/codehaus/groovy/classgen/asm/sc/Groovy6955Support$Request.getHeaders')
         }
     }
+
+    // GROOVY-7597
+    void testImplicitDelegateShouldNotBeCheckedAsTypeOfPropertyOwner() {
+        try {
+            assertScript '''
+                class Calculation {
+                    boolean isValid() { true }
+                }
+
+                class Entity {
+                    Calculation getCalculation(String name) { new Calculation() }
+                }
+
+                class Handler {
+                    def doWithEntity(@DelegatesTo(Entity) Closure c) {
+                        new Entity().with(c)
+                    }
+
+                    def doIt() {
+                        doWithEntity() {
+                            getCalculation("whatever").valid
+                        }
+                    }
+                }
+
+                assert new Handler().doIt()
+            '''
+        } finally {
+            def bytecode = astTrees['Handler$_doIt_closure1'][1]
+            assert !bytecode.contains('CHECKCAST Calculation')
+            assert !bytecode.contains('INVOKESTATIC org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType')
+        }
+    }
 }
\ No newline at end of file


[5/5] incubator-groovy git commit: GROOVY-7618 Parameterless closure to SAM Type argument coercion causes NPE during instruction selection (STC)

Posted by cc...@apache.org.
GROOVY-7618 Parameterless closure to SAM Type argument coercion causes NPE during instruction selection (STC)

Closes #135


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

Branch: refs/heads/master
Commit: baba6dfdf46f3d8d7025ff319a875d4bcbdce80f
Parents: 50e422b
Author: Shil S <sh...@gmail.com>
Authored: Wed Oct 7 00:21:51 2015 -0400
Committer: Cedric Champeau <cc...@apache.org>
Committed: Wed Oct 7 21:15:47 2015 +0200

----------------------------------------------------------------------
 .../transform/stc/StaticTypeCheckingVisitor.java      |  5 ++++-
 src/test/groovy/transform/stc/ClosuresSTCTest.groovy  | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/baba6dfd/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 1348fb8..c09e12b 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2365,7 +2365,10 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
         ClassNode[] blockParameterTypes = (ClassNode[]) openBlock.getNodeMetaData(StaticTypesMarker.CLOSURE_ARGUMENTS);
         if (blockParameterTypes==null) {
             Parameter[] p = openBlock.getParameters();
-            if (p.length==0 && parameterTypesForSAM.length!=0) {
+            if (p == null) {
+                // zero parameter closure e.g. { -> println 'no args' }
+                blockParameterTypes = ClassNode.EMPTY_ARRAY;
+            } else if (p.length==0 && parameterTypesForSAM.length!=0) {
                 // implicit it
                 blockParameterTypes = parameterTypesForSAM;
             } else {

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/baba6dfd/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
index fae7988..1eaeca8 100644
--- a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
@@ -500,5 +500,19 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
             A.doSomething()
         '''
     }
+
+    void testParameterlessClosureToSAMTypeArgumentCoercion() {
+        assertScript '''
+            interface SamType {
+                int sam()
+            }
+
+            int foo(SamType samt) {
+                samt.sam()
+            }
+
+            assert foo { -> 1 }  == 1
+        '''
+    }
 }
 


[4/5] incubator-groovy git commit: Additions to @DelegatesTo javadoc

Posted by cc...@apache.org.
Additions to @DelegatesTo javadoc

Closes #134


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

Branch: refs/heads/master
Commit: 50e422b845493567b1be30ef61e99cd6104ec333
Parents: 020a942
Author: Shil S <sh...@gmail.com>
Authored: Tue Oct 6 18:20:27 2015 -0400
Committer: Cedric Champeau <cc...@apache.org>
Committed: Wed Oct 7 21:13:59 2015 +0200

----------------------------------------------------------------------
 src/main/groovy/lang/DelegatesTo.java | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/50e422b8/src/main/groovy/lang/DelegatesTo.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/DelegatesTo.java b/src/main/groovy/lang/DelegatesTo.java
index cb2f103..54a5e36 100644
--- a/src/main/groovy/lang/DelegatesTo.java
+++ b/src/main/groovy/lang/DelegatesTo.java
@@ -48,16 +48,30 @@ import java.lang.annotation.Target;
 @Target({ElementType.PARAMETER})
 public @interface DelegatesTo {
     Class value() default Target.class;
+
+    /**
+     * The {@link Closure#resolveStrategy} used by the closure.
+     */
     int strategy() default Closure.OWNER_FIRST;
+
+    /**
+     * The index of the generic type that will be the type of the closure's delegate.
+     * The generic types are considered with respect to the {@code @DelegatesTo.Target} annotated
+     * parameter for this usage, with the index starting at 0.
+     */
     int genericTypeIndex() default -1;
 
+    /**
+     * In cases when there are multiple {@code @DelegatesTo.Target} annotated parameters, this
+     * member should be set to the {@link DelegatesTo.Target#value()} of the correct target.
+     */
     String target() default "";
 
     /**
-     * The type member should be used when the type of the delagate cannot
+     * The type member should be used when the type of the delegate cannot
      * be represented with {@link #value()}, {@link #genericTypeIndex()} or
      * {@link #target()}. In this case, it is possible to use a String to represent
-     * the type, at the cost of potential uncatched errors at compile time if the
+     * the type, at the cost of potential uncaught errors at compile time if the
      * type is invalid and increased compile time.
      *
      * @return a String representation of a type
@@ -65,9 +79,18 @@ public @interface DelegatesTo {
      */
     String type() default "";
 
+    /**
+     * Parameter annotation used to specify the delegate for a {@code @DelegatesTo} annotated
+     * parameter of the same method.
+     */
     @Retention(RetentionPolicy.RUNTIME)
     @java.lang.annotation.Target({ElementType.PARAMETER})
     public static @interface Target {
-        String value() default ""; // optional id
+
+        /**
+         * An identifier that should be used to disambiguate targets when there are
+         * multiple {@code @DelegatesTo.Target} annotated parameters.
+         */
+        String value() default "";
     }
 }
\ No newline at end of file