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 2023/12/24 12:02:21 UTC

(groovy) branch GROOVY_3_0_X updated (a54d871388 -> 56e739270b)

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

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


    from a54d871388 Bump version on GROOVY_3_0_X branch
     new bb637371bc GROOVY-11046: defer class header parsing for reference w/o type argument
     new 56e739270b GROOVY-11257: STC: propagate receiver type for property accessor return

The 2 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.


Summary of changes:
 .../codehaus/groovy/control/GenericsVisitor.java   |  2 +-
 .../transform/stc/StaticTypeCheckingVisitor.java   |  2 +-
 .../bugs/{Groovy9566.groovy => Groovy11046.groovy} |  8 +++--
 .../groovy/transform/stc/GenericsSTCTest.groovy    | 18 ++++++++++
 ...HelperPrecompiledJava.java => Groovy11257.java} |  6 ++--
 .../IncrementalRecompilationWithStubsTest.groovy   | 41 +++++++++++-----------
 .../groovy/tools/stubgenerator/StubTestCase.groovy | 16 ++++-----
 7 files changed, 58 insertions(+), 35 deletions(-)
 copy src/test/groovy/bugs/{Groovy9566.groovy => Groovy11046.groovy} (77%)
 copy src/test/groovy/transform/stc/{Groovy7907HelperPrecompiledJava.java => Groovy11257.java} (87%)


(groovy) 02/02: GROOVY-11257: STC: propagate receiver type for property accessor return

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

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

commit 56e739270b758860a80f84d94411b80e0078e09e
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Dec 24 04:29:08 2023 -0600

    GROOVY-11257: STC: propagate receiver type for property accessor return
---
 .../transform/stc/StaticTypeCheckingVisitor.java   |  2 +-
 .../groovy/transform/stc/GenericsSTCTest.groovy    | 18 ++++++++++++++++
 src/test/groovy/transform/stc/Groovy11257.java     | 25 ++++++++++++++++++++++
 3 files changed, 44 insertions(+), 1 deletion(-)

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 cc81ef376c..3f20492f73 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1598,7 +1598,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                 if (property == null || !enclosingTypes.contains(receiverType)) {
                     if (readMode) {
                         if (getter != null) {
-                            ClassNode returnType = inferReturnTypeGenerics(current, getter, ArgumentListExpression.EMPTY_ARGUMENTS);
+                            ClassNode returnType = inferReturnTypeGenerics(receiverType, getter, ArgumentListExpression.EMPTY_ARGUMENTS);
                             storeInferredTypeForPropertyExpression(pexp, returnType);
                             storeTargetMethod(pexp, getter);
                             String delegationData = receiver.getData();
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index a2726aeede..4c332bdf13 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -937,6 +937,24 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-11257
+    void testReturnTypeInferenceWithMethodGenerics31() {
+        assertScript '''
+            interface I<U> extends groovy.transform.stc.Groovy11257<U> {}
+            def <V> I<V> forge(V v) { return new I(){} }
+            void test() {
+                @ASTTest(phase=INSTRUCTION_SELECTION, value={
+                    def type = node.getNodeMetaData(INFERRED_TYPE)
+                    assert type.toString(false) == 'java.util.Optional <java.math.BigInteger>'
+                })
+                def opt = forge(1G).thing
+                def num = opt.orElse(42G).intValue()
+            }
+
+            test()
+        '''
+    }
+
     void testDiamondInferenceFromConstructor1() {
         assertScript '''
             class Foo<U> {
diff --git a/src/test/groovy/transform/stc/Groovy11257.java b/src/test/groovy/transform/stc/Groovy11257.java
new file mode 100644
index 0000000000..e63a7cb912
--- /dev/null
+++ b/src/test/groovy/transform/stc/Groovy11257.java
@@ -0,0 +1,25 @@
+/*
+ *  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 groovy.transform.stc;
+
+import java.util.Optional;
+
+public interface Groovy11257<T> {
+    default Optional<T> getThing() { return Optional.empty(); }
+}


(groovy) 01/02: GROOVY-11046: defer class header parsing for reference w/o type argument

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

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

commit bb637371bcde33efc518cc58eed2335b11a7775e
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Dec 20 13:48:39 2023 -0600

    GROOVY-11046: defer class header parsing for reference w/o type argument
---
 .../codehaus/groovy/control/GenericsVisitor.java   |  2 +-
 src/test/groovy/bugs/Groovy11046.groovy            | 34 ++++++++++++++++++
 .../IncrementalRecompilationWithStubsTest.groovy   | 41 +++++++++++-----------
 .../groovy/tools/stubgenerator/StubTestCase.groovy | 16 ++++-----
 4 files changed, 64 insertions(+), 29 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/control/GenericsVisitor.java b/src/main/java/org/codehaus/groovy/control/GenericsVisitor.java
index 07a17a6e2b..3ad3fb3025 100644
--- a/src/main/java/org/codehaus/groovy/control/GenericsVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/GenericsVisitor.java
@@ -154,9 +154,9 @@ public class GenericsVisitor extends ClassCodeVisitorSupport {
     private void checkGenericsUsage(final ClassNode cn, final ClassNode rn, final Boolean isAIC) {
         if (cn.isGenericsPlaceHolder()) return;
         GenericsType[] cnTypes = cn.getGenericsTypes();
-        GenericsType[] rnTypes = rn.getGenericsTypes();
         // raw type usage is always allowed
         if (cnTypes == null) return;
+        GenericsType[] rnTypes = rn.getGenericsTypes();
         // you can't parameterize a non-generified type
         if (rnTypes == null) {
             String message = "The class " + cn.toString(false) + " (supplied with " + plural("type parameter", cnTypes.length) +
diff --git a/src/test/groovy/bugs/Groovy11046.groovy b/src/test/groovy/bugs/Groovy11046.groovy
new file mode 100644
index 0000000000..e405cf1337
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy11046.groovy
@@ -0,0 +1,34 @@
+/*
+ *  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 groovy.bugs
+
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy11046 {
+    @Test
+    void testGrabErrorForMissingDependency() {
+        // throws NoClassDefFoundError: com.lmax.disruptor.EventTranslatorVararg
+        assertScript '''
+            @Grab('org.apache.logging.log4j:log4j-core:2.22.0')
+            org.apache.logging.log4j.core.async.AsyncLogger log
+        '''
+    }
+}
diff --git a/src/test/org/codehaus/groovy/ast/decompiled/IncrementalRecompilationWithStubsTest.groovy b/src/test/org/codehaus/groovy/ast/decompiled/IncrementalRecompilationWithStubsTest.groovy
index 017c4ba243..8f23b512cf 100644
--- a/src/test/org/codehaus/groovy/ast/decompiled/IncrementalRecompilationWithStubsTest.groovy
+++ b/src/test/org/codehaus/groovy/ast/decompiled/IncrementalRecompilationWithStubsTest.groovy
@@ -20,35 +20,36 @@ package org.codehaus.groovy.ast.decompiled
 
 import org.codehaus.groovy.tools.stubgenerator.StubTestCase
 
-class IncrementalRecompilationWithStubsTest extends StubTestCase {
+final class IncrementalRecompilationWithStubsTest extends StubTestCase {
+
+    private static File createFile(File dir, String name, String text) {
+        new File(dir, name).tap {
+            createNewFile()
+            setText(text)
+        }
+    }
+
     @Override
     void testRun() {
         configure()
-        File srcDir = createTempDirectory()
-        srcDir.deleteOnExit()
 
-        File src1 = createFile(srcDir, "AsmClass1.groovy", "class AsmClass1 {}")
-        File src2 = createFile(srcDir, "AsmClass2.groovy", "class AsmClass2 extends AsmClass1 {}")
-        File src3 = createFile(srcDir, "AsmClass3.groovy", "class AsmClass3 extends AsmClass2 {}")
-        File javaSrc = createFile(srcDir, "JavaClass.java", "class JavaClass {}")
+        File groovy1 = createFile(stubDir, "AsmClass1.groovy", "class AsmClass1 {}")
+        File groovy2 = createFile(stubDir, "AsmClass2.groovy", "class AsmClass2 extends AsmClass1 {}")
+        File groovy3 = createFile(stubDir, "AsmClass3.groovy", "class AsmClass3 extends AsmClass2 {}")
+        File javaOne = createFile(stubDir, "JavaClass.java"  , "class JavaClass {}")
 
-        compile([src1, src2, src3, javaSrc])
+        compile([groovy1, groovy2, groovy3, javaOne])
 
-        def cls1 = new File(targetDir, "AsmClass1.class")
-        assert cls1.exists()
-        assert cls1.delete()
+        File   class1 = new File(targetDir, "AsmClass1.class")
+        assert class1.exists()
+        assert class1.delete()
 
-        compile([src1, src3, javaSrc])
-        assert cls1.exists()
-    }
+        compile([groovy1, groovy3, javaOne])
 
-    private static File createFile(File srcDir, String name, String text) {
-        File srcFile = new File(srcDir, name)
-        assert srcFile.createNewFile()
-        srcFile.text = text
-        return srcFile
+        assert class1.exists()
     }
 
     @Override
-    void verifyStubs() {}
+    void verifyStubs() {
+    }
 }
diff --git a/src/test/org/codehaus/groovy/tools/stubgenerator/StubTestCase.groovy b/src/test/org/codehaus/groovy/tools/stubgenerator/StubTestCase.groovy
index a9e9d3979e..0e73a5e118 100644
--- a/src/test/org/codehaus/groovy/tools/stubgenerator/StubTestCase.groovy
+++ b/src/test/org/codehaus/groovy/tools/stubgenerator/StubTestCase.groovy
@@ -74,8 +74,7 @@ abstract class StubTestCase extends GroovyTestCase {
      * Prepare the target and stub directories.
      */
     protected void setUp() {
-        // TODO: commented super.setUp() as it generates a stackoverflow, for some reason?!
-        // super.setUp()
+        super.setUp()
         if (debug) {
             println """\
                 Stub generator test [${this.class.name}]
@@ -91,7 +90,7 @@ abstract class StubTestCase extends GroovyTestCase {
      * Delete the temporary directories.
      */
     protected void tearDown() {
-        if(delete) {
+        if (delete) {
             if (debug) println "Deleting temporary folders"
             targetDir.deleteDir()
             stubDir.deleteDir()
@@ -115,7 +114,8 @@ abstract class StubTestCase extends GroovyTestCase {
      *     }
      * </code></pre>
      */
-    protected void init() {}
+    protected void init() {
+    }
 
     /**
      * @return the folder containing the sample Groovy and Java sources for the test
@@ -270,7 +270,7 @@ abstract class StubTestCase extends GroovyTestCase {
     /**
      * All tests must implement this method, for doing
      */
-    abstract void verifyStubs()
+    protected abstract void verifyStubs()
 
     /**
      * Method providing a useful shortcut for the subclasses, so that you can use <code>classes</code>
@@ -314,18 +314,18 @@ abstract class StubTestCase extends GroovyTestCase {
     protected static void createNecessaryPackageDirs(File path, String relativeFilePath) {
         def index = relativeFilePath.lastIndexOf('/')
 
-        if(index < 0) return
+        if (index < 0) return
 
         def relativeDirectories = relativeFilePath.substring(0, index)
 
         def tmpPath = path.absolutePath
 
         relativeDirectories.split('/').each {
-            if(!tmpPath.endsWith(File.separator)) {
+            if (!tmpPath.endsWith(File.separator)) {
                 tmpPath = tmpPath + File.separator
             }
             File newDir = new File(tmpPath + it)
-            if(!newDir.exists()) {
+            if (!newDir.exists()) {
                 if (!(newDir.mkdir())) {
                     throw new IOException("Impossible to create package directory: ${newDir.absolutePath}")
                 }