You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2021/05/24 00:18:54 UTC

[groovy] branch GROOVY-10104 created (now f29815b)

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a change to branch GROOVY-10104
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at f29815b  GROOVY-6851, GROOVY-9151, GROOVY-10104: SC: skip Verifier generated node

This branch includes the following new commits:

     new f29815b  GROOVY-6851, GROOVY-9151, GROOVY-10104: SC: skip Verifier generated node

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[groovy] 01/01: GROOVY-6851, GROOVY-9151, GROOVY-10104: SC: skip Verifier generated node

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY-10104
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit f29815b848f63bffd84528ceaae76ab85c82dc30
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun May 23 19:09:21 2021 -0500

    GROOVY-6851, GROOVY-9151, GROOVY-10104: SC: skip Verifier generated node
---
 .../transform/sc/StaticCompilationVisitor.java     | 17 ++++++-----
 .../transform/stc/StaticTypeCheckingVisitor.java   | 20 +------------
 src/test/gls/invocation/DefaultParamTest.groovy    | 23 +++++++++++++++
 .../classgen/asm/sc/BugsStaticCompileTest.groovy   | 33 +++++++++-------------
 4 files changed, 47 insertions(+), 46 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/sc/StaticCompilationVisitor.java b/src/main/java/org/codehaus/groovy/transform/sc/StaticCompilationVisitor.java
index ceda968..da07917 100644
--- a/src/main/java/org/codehaus/groovy/transform/sc/StaticCompilationVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/sc/StaticCompilationVisitor.java
@@ -69,6 +69,8 @@ import java.util.Set;
 import static org.codehaus.groovy.ast.ClassHelper.LIST_TYPE;
 import static org.codehaus.groovy.ast.ClassHelper.OBJECT_TYPE;
 import static org.codehaus.groovy.ast.ClassHelper.int_TYPE;
+import static org.codehaus.groovy.ast.ClassHelper.isStringType;
+import static org.codehaus.groovy.ast.ClassHelper.isWrapperCharacter;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.args;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.assignS;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.attrX;
@@ -83,8 +85,7 @@ import static org.codehaus.groovy.ast.tools.GenericsUtils.applyGenericsContextTo
 import static org.codehaus.groovy.ast.tools.GenericsUtils.correctToGenericsSpecRecurse;
 import static org.codehaus.groovy.ast.tools.GenericsUtils.createGenericsSpec;
 import static org.codehaus.groovy.ast.tools.GenericsUtils.extractSuperClassGenerics;
-import static org.codehaus.groovy.ast.ClassHelper.isStringType;
-import static org.codehaus.groovy.ast.ClassHelper.isWrapperCharacter;
+import static org.codehaus.groovy.classgen.Verifier.DEFAULT_PARAMETER_GENERATED;
 import static org.codehaus.groovy.transform.sc.StaticCompilationMetadataKeys.BINARY_EXP_TARGET;
 import static org.codehaus.groovy.transform.sc.StaticCompilationMetadataKeys.COMPONENT_TYPE;
 import static org.codehaus.groovy.transform.sc.StaticCompilationMetadataKeys.DYNAMIC_OUTER_NODE_CALLBACK;
@@ -139,13 +140,15 @@ public class StaticCompilationVisitor extends StaticTypeCheckingVisitor {
     }
 
     public static boolean isStaticallyCompiled(final AnnotatedNode node) {
-        if (node.getNodeMetaData(STATIC_COMPILE_NODE) != null) {
-            return (Boolean) node.getNodeMetaData(STATIC_COMPILE_NODE);
+        if (node != null && node.getNodeMetaData(STATIC_COMPILE_NODE) != null) {
+            return Boolean.TRUE.equals(node.getNodeMetaData(STATIC_COMPILE_NODE));
         }
         if (node instanceof MethodNode) {
-            return isStaticallyCompiled(node.getDeclaringClass());
-        }
-        if (node instanceof ClassNode && ((ClassNode) node).getOuterClass() != null) {
+            // GROOVY-6851, GROOVY-9151, GROOVY-10104
+            if (!Boolean.TRUE.equals(node.getNodeMetaData(DEFAULT_PARAMETER_GENERATED))) {
+                return isStaticallyCompiled(node.getDeclaringClass());
+            }
+        } else if (node instanceof ClassNode) {
             return isStaticallyCompiled(((ClassNode) node).getOuterClass());
         }
         return false;
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 93fdbf9..b7677bd 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2575,11 +2575,6 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
             // method has already been visited by a static type checking visitor
             return;
         }
-        for (Parameter parameter : node.getParameters()) {
-            if (parameter.getInitialExpression() != null) {
-                parameter.getInitialExpression().visit(this);
-            }
-        }
         super.visitConstructor(node);
     }
 
@@ -2600,27 +2595,14 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
         typeCheckingContext.alreadyVisitedMethods.add(node);
 
         typeCheckingContext.pushErrorCollector(collector);
-
         boolean osc = typeCheckingContext.isInStaticContext;
         try {
             typeCheckingContext.isInStaticContext = node.isStatic();
+
             super.visitMethod(node);
-            for (Parameter parameter : node.getParameters()) {
-                if (parameter.getInitialExpression() != null) {
-                    parameter.getInitialExpression().visit(this);
-                }
-            }
-/*
-            ClassNode rtype = getInferredReturnType(node);
-            if (rtype == null) {
-                storeInferredReturnType(node, node.getReturnType());
-            }
-            addTypeCheckingInfoAnnotation(node);
-*/
         } finally {
             typeCheckingContext.isInStaticContext = osc;
         }
-
         typeCheckingContext.popErrorCollector();
         node.putNodeMetaData(ERROR_COLLECTOR, collector);
     }
diff --git a/src/test/gls/invocation/DefaultParamTest.groovy b/src/test/gls/invocation/DefaultParamTest.groovy
index 341e681..1dad4df 100644
--- a/src/test/gls/invocation/DefaultParamTest.groovy
+++ b/src/test/gls/invocation/DefaultParamTest.groovy
@@ -139,6 +139,29 @@ final class DefaultParamTest extends GroovyTestCase {
         '''
     }
 
+    // GROOVY-6851, GROOVY-9151, GROOVY-10104
+    void testMethodWithAllParametersDefaultedCS() {
+        assertScript '''
+            @groovy.transform.CompileStatic
+            String greet(Object o = 'world', String s = o.toString()) {
+                "hello $s"
+            }
+            assert greet() == 'hello world'
+        '''
+
+        assertScript '''
+            @groovy.transform.CompileStatic
+            class Main {
+                static main(args) {
+                    assert new Main().test().isEmpty()
+                }
+                Map test(Map<String, Object> m = new HashMap<>(Collections.emptyMap())) {
+                    return m
+                }
+            }
+        '''
+    }
+
     // GROOVY-9151
     void testConstructorWithAllParametersDefaulted() {
         assertScript '''
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 b8c41d6..0377642 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
@@ -1200,27 +1200,20 @@ assert it.next() == 1G
 
     // GROOVY-6851
     void testShouldNotThrowNPEIfElvisOperatorIsUsedInDefaultArgumentValue() {
-        assertScript '''import org.codehaus.groovy.ast.expr.MethodCallExpression
-
-class GrailsHomeWorkspaceReader {
-    @ASTTest(phase=INSTRUCTION_SELECTION,value={
-        def defaultValue = node.parameters[0].initialExpression
-        assert defaultValue instanceof MethodCallExpression
-        def target = defaultValue.getNodeMetaData(DIRECT_METHOD_CALL_TARGET)
-        assert target != null
-    })
-    GrailsHomeWorkspaceReader(String grailsHome = System.getProperty('grails.home')) {
-    }
-}
-new GrailsHomeWorkspaceReader()
-'''
         assertScript '''
-class GrailsHomeWorkspaceReader {
-    GrailsHomeWorkspaceReader(String grailsHome = System.getProperty('grails.home') ?: System.getenv('GRAILS_HOME')) {
-    }
-}
-new GrailsHomeWorkspaceReader()
-'''
+            class GrailsHomeWorkspaceReader {
+                GrailsHomeWorkspaceReader(String grailsHome = System.getProperty('grails.home')) {
+                }
+            }
+            new GrailsHomeWorkspaceReader()
+        '''
+        assertScript '''
+            class GrailsHomeWorkspaceReader {
+                GrailsHomeWorkspaceReader(String grailsHome = System.getProperty('grails.home') ?: System.getenv('GRAILS_HOME')) {
+                }
+            }
+            new GrailsHomeWorkspaceReader()
+            '''
     }
 
     // GROOVY-6342