[groovy] branch GROOVY_3_0_X updated (bacee81 -> 8a843a5)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[groovy] branch GROOVY_3_0_X updated (bacee81 -> 8a843a5)

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

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


    from bacee81  fix merge glitch
     new fa3bcf8  Adds workflow to verify Groovy and Micronaut integration
     new 42fd684  Expands Micronaut joint validation to include all test tasks in Micronaut Core (closes #1424)
     new 480c4b7  GROOVY-9821: STC: check "T" from "? extends T" for spread property (port to 3_0_X)
     new 8a843a5  GROOVY-9822: check for empty spec before recursive application (port to 3_0_X)

The 4 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:
 ...lidation.yml => micronaut-joint-validation.yml} | 37 ++++----
 .../transform/stc/StaticTypeCheckingSupport.java   | 60 +++++++------
 .../transform/stc/StaticTypeCheckingVisitor.java   | 43 +++++-----
 .../groovy/transform/stc/GenericsSTCTest.groovy    | 98 +++++++++++++++++++++-
 4 files changed, 170 insertions(+), 68 deletions(-)
 copy .github/workflows/{grails-joint-validation.yml => micronaut-joint-validation.yml} (61%)

Reply | Threaded
Open this post in threaded view
|

[groovy] 01/04: Adds workflow to verify Groovy and Micronaut integration

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

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

commit fa3bcf81675277bd76b8031dc626af4bd4ad3d21
Author: Jason Schindler <[hidden email]>
AuthorDate: Wed Nov 18 16:27:51 2020 -0600

    Adds workflow to verify Groovy and Micronaut integration
---
 .github/workflows/micronaut-joint-validation.yml | 67 ++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/.github/workflows/micronaut-joint-validation.yml b/.github/workflows/micronaut-joint-validation.yml
new file mode 100644
index 0000000..4c136e3
--- /dev/null
+++ b/.github/workflows/micronaut-joint-validation.yml
@@ -0,0 +1,67 @@
+# 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.
+
+name: "Micronaut Joint Validation Build"
+on:
+  push:
+    branches:
+      - GROOVY_3_0_X
+  pull_request:
+    branches:
+      - GROOVY_3_0_X
+jobs:
+  build:
+    strategy:
+      fail-fast: true
+      matrix:
+        os: [ubuntu-18.04]
+        java: [11.0.6]
+    runs-on: ${{ matrix.os }}
+    steps:
+      - uses: actions/checkout@v1
+      - name: Set up JDK
+        uses: actions/setup-java@v1
+        with:
+          java-version: ${{ matrix.java }}
+      - name: env
+        run: env
+
+      # Create mavenLocal init script
+      - name: Create init script to enable mavenLocal()
+        run: cd .. && echo "allprojects { repositories { mavenLocal() } }" > maven-local-init.gradle
+
+      # Clone Micronaut Repos
+      - name: Checkout Micronaut Core
+        run: cd .. && git clone --depth 1 https://github.com/micronaut-projects/micronaut-core -b 2.2.x
+
+      - name: Checkout Micronaut Groovy
+        run: cd .. && git clone --depth 1 https://github.com/micronaut-projects/micronaut-groovy -b master
+
+      - name: Build and install groovy (no docs)
+        run: ./gradlew clean install -x groovydoc -x javadoc -x javadocAll -x groovydocAll -x asciidoc -x docGDK --no-build-cache --no-scan --no-daemon
+        timeout-minutes: 60
+
+      - name: Set CI_GROOVY_VERSION
+        run: echo "CI_GROOVY_VERSION=$(cat gradle.properties | grep groovyVersion | cut -d\= -f2 |  tr -d '[:space:]')" >> $GITHUB_ENV
+      - name: echo CI_GROOVY_VERSION
+        run: echo $CI_GROOVY_VERSION
+
+      - name: Check Micronaut Core
+        run: cd ../micronaut-core && ./gradlew clean inject-groovy:check test-suite-groovy:check --no-build-cache --no-scan --no-daemon -PgroovyVersion=$CI_GROOVY_VERSION --init-script ../maven-local-init.gradle
+        timeout-minutes: 60
+
+      - name: Check Micronaut Groovy
+        run: cd ../micronaut-groovy && ./gradlew clean check --no-build-cache --no-scan --no-daemon -PgroovyVersion=$CI_GROOVY_VERSION --init-script ../maven-local-init.gradle
+        timeout-minutes: 60

Reply | Threaded
Open this post in threaded view
|

[groovy] 02/04: Expands Micronaut joint validation to include all test tasks in Micronaut Core (closes #1424)

paulk
In reply to this post by paulk
This is an automated email from the ASF dual-hosted git repository.

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

commit 42fd684c2dd2bd37c88ebe8fd4238f44ec3e5d5f
Author: Jason Schindler <[hidden email]>
AuthorDate: Thu Nov 19 12:06:05 2020 -0600

    Expands Micronaut joint validation to include all test tasks in Micronaut Core (closes #1424)
---
 .github/workflows/micronaut-joint-validation.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/micronaut-joint-validation.yml b/.github/workflows/micronaut-joint-validation.yml
index 4c136e3..0f5e89c 100644
--- a/.github/workflows/micronaut-joint-validation.yml
+++ b/.github/workflows/micronaut-joint-validation.yml
@@ -59,7 +59,7 @@ jobs:
         run: echo $CI_GROOVY_VERSION
 
       - name: Check Micronaut Core
-        run: cd ../micronaut-core && ./gradlew clean inject-groovy:check test-suite-groovy:check --no-build-cache --no-scan --no-daemon -PgroovyVersion=$CI_GROOVY_VERSION --init-script ../maven-local-init.gradle
+        run: cd ../micronaut-core && ./gradlew clean check --no-build-cache --no-scan --no-daemon -PgroovyVersion=$CI_GROOVY_VERSION --init-script ../maven-local-init.gradle
         timeout-minutes: 60
 
       - name: Check Micronaut Groovy

Reply | Threaded
Open this post in threaded view
|

[groovy] 03/04: GROOVY-9821: STC: check "T" from "? extends T" for spread property (port to 3_0_X)

paulk
In reply to this post by paulk
This is an automated email from the ASF dual-hosted git repository.

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

commit 480c4b7421abfd43993fc6d1498c08f332189b05
Author: Eric Milles <[hidden email]>
AuthorDate: Thu Nov 19 15:29:06 2020 -0600

    GROOVY-9821: STC: check "T" from "? extends T" for spread property (port to 3_0_X)
---
 .../transform/stc/StaticTypeCheckingSupport.java   |  2 +-
 .../transform/stc/StaticTypeCheckingVisitor.java   | 43 +++++++++++-----------
 .../groovy/transform/stc/GenericsSTCTest.groovy    | 32 ++++++++++++++++
 3 files changed, 54 insertions(+), 23 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index c181dd3..bf79605 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1897,7 +1897,7 @@ public abstract class StaticTypeCheckingSupport {
         return newBound;
     }
 
-    private static ClassNode getCombinedBoundType(final GenericsType genericsType) {
+    static ClassNode getCombinedBoundType(final GenericsType genericsType) {
         // TODO: this method should really return some kind of meta ClassNode
         // representing the combination of all bounds. The code here, just picks
         // something out to be able to proceed and is not actually correct
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 923346d..0b444fa 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -188,6 +188,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.constX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.getSetterName;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.isOrImplements;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.localVarX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.propX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.thisPropX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.varX;
 import static org.codehaus.groovy.ast.tools.GenericsUtils.toGenericTypesString;
@@ -245,6 +246,7 @@ import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findDG
 import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findSetters;
 import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findTargetVariable;
 import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.fullyResolveType;
+import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getCombinedBoundType;
 import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getCorrectedClassNode;
 import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getGenericsWithoutArray;
 import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getOperationName;
@@ -897,12 +899,10 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
     }
 
     private void validateResourceInARM(final BinaryExpression expression, final ClassNode lType) {
-        if (expression instanceof DeclarationExpression) {
-            if (TryCatchStatement.isResource(expression)) {
-                if (!lType.implementsInterface(AUTOCLOSEABLE_TYPE)) {
-                    addError("Resource[" + lType.getName() + "] in ARM should be of type AutoCloseable", expression);
-                }
-            }
+        if (expression instanceof DeclarationExpression
+                && TryCatchStatement.isResource(expression)
+                && !isOrImplements(lType, AUTOCLOSEABLE_TYPE)) {
+            addError("Resource[" + lType.getName() + "] in ARM should be of type AutoCloseable", expression);
         }
     }
 
@@ -1661,21 +1661,20 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
     }
 
     private ClassNode getTypeForSpreadExpression(final ClassNode testClass, final ClassNode objectExpressionType, final PropertyExpression pexp) {
-        if (!pexp.isSpreadSafe()) return null;
-        MethodCallExpression mce = callX(varX("_", testClass), "iterator", ArgumentListExpression.EMPTY_ARGUMENTS);
-        mce.setImplicitThis(false);
-        mce.visit(this);
-        ClassNode callType = getType(mce);
-        if (!implementsInterfaceOrIsSubclassOf(callType, Iterator_TYPE)) return null;
-        GenericsType[] types = callType.getGenericsTypes();
-        ClassNode contentType = OBJECT_TYPE;
-        if (types != null && types.length == 1) contentType = types[0].getType();
-        PropertyExpression subExp = new PropertyExpression(varX("{}", contentType), pexp.getPropertyAsString());
-        AtomicReference<ClassNode> result = new AtomicReference<>();
-        if (existsProperty(subExp, true, new PropertyLookupVisitor(result))) {
-            ClassNode intf = LIST_TYPE.getPlainNodeReference();
-            intf.setGenericsTypes(new GenericsType[]{new GenericsType(getWrapper(result.get()))});
-            return intf;
+        if (pexp.isSpreadSafe()) {
+            MethodCallExpression mce = callX(varX("_", testClass), "iterator");
+            mce.setImplicitThis(false);
+            mce.visit(this);
+            ClassNode iteratorType = getType(mce);
+            if (isOrImplements(iteratorType, Iterator_TYPE)) {
+                GenericsType[] gts = iteratorType.getGenericsTypes();
+                ClassNode itemType = (gts != null && gts.length == 1 ? getCombinedBoundType(gts[0]) : OBJECT_TYPE);
+
+                AtomicReference<ClassNode> propertyType = new AtomicReference<>();
+                if (existsProperty(propX(varX("{}", itemType), pexp.getProperty()), true, new PropertyLookupVisitor(propertyType))) {
+                    return extension.buildListType(propertyType.get());
+                }
+            }
         }
         return null;
     }
@@ -2236,7 +2235,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
 
     private boolean looksLikeNamedArgConstructor(final ClassNode receiver, final ClassNode[] argumentTypes) {
         if (argumentTypes.length == 1 || argumentTypes.length == 2 && argumentTypes[0].equals(receiver.getOuterClass())) {
-            return argumentTypes[argumentTypes.length - 1].implementsInterface(MAP_TYPE);
+            return isOrImplements(argumentTypes[argumentTypes.length - 1], MAP_TYPE);
         }
         return false;
     }
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 72b5272..8e568c7 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -2096,6 +2096,38 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
             }
             null
         '''
+
+        // GROOVY-9821
+        config.with {
+            targetDirectory = File.createTempDir()
+            jointCompilationOptions = [memStub: true]
+        }
+        File parentDir = File.createTempDir()
+        try {
+            def a = new File(parentDir, 'Types.java')
+            a.write '''
+                interface A {
+                    java.util.Collection<? extends B> getBees();
+                }
+                interface B {
+                    Object getC();
+                }
+            '''
+            def b = new File(parentDir, 'Script.groovy')
+            b.write '''
+                def test(A a) {
+                    a.bees*.c
+                }
+            '''
+
+            def loader = new GroovyClassLoader(this.class.classLoader)
+            def cu = new JavaAwareCompilationUnit(config, loader)
+            cu.addSources(a, b)
+            cu.compile()
+        } finally {
+            parentDir.deleteDir()
+            config.targetDirectory.deleteDir()
+        }
     }
 
     // GROOVY-7804

Reply | Threaded
Open this post in threaded view
|

[groovy] 04/04: GROOVY-9822: check for empty spec before recursive application (port to 3_0_X)

paulk
In reply to this post by paulk
This is an automated email from the ASF dual-hosted git repository.

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

commit 8a843a5cdffe49b5880f26bd6ab465d65362a1bd
Author: Eric Milles <[hidden email]>
AuthorDate: Thu Nov 19 11:55:29 2020 -0600

    GROOVY-9822: check for empty spec before recursive application (port to 3_0_X)
---
 .../transform/stc/StaticTypeCheckingSupport.java   | 70 ++++++++++++----------
 .../groovy/transform/stc/GenericsSTCTest.groovy    | 66 +++++++++++++++++++-
 2 files changed, 103 insertions(+), 33 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index bf79605..f890e36 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1863,38 +1863,44 @@ public abstract class StaticTypeCheckingSupport {
         return false;
     }
 
-    private static ClassNode[] applyGenericsContext(final Map<GenericsTypeName, GenericsType> spec, final ClassNode[] bounds) {
-        if (bounds == null) return null;
-        ClassNode[] newBounds = new ClassNode[bounds.length];
-        for (int i = 0, n = bounds.length; i < n; i += 1) {
-            newBounds[i] = applyGenericsContext(spec, bounds[i]);
-        }
-        return newBounds;
-    }
-
-    static ClassNode applyGenericsContext(final Map<GenericsTypeName, GenericsType> spec, final ClassNode bound) {
-        if (bound == null) return null;
-        if (bound.isArray()) {
-            return applyGenericsContext(spec, bound.getComponentType()).makeArray();
-        }
-        if (!bound.isUsingGenerics()) return bound;
-        ClassNode newBound = bound.getPlainNodeReference();
-        newBound.setGenericsTypes(applyGenericsContext(spec, bound.getGenericsTypes()));
-        if (bound.isGenericsPlaceHolder()) {
-            GenericsType[] gt = newBound.getGenericsTypes();
-            boolean hasBounds = hasNonTrivialBounds(gt[0]);
-            if (hasBounds || !gt[0].isPlaceholder()) return getCombinedBoundType(gt[0]);
-            String placeHolderName = newBound.getGenericsTypes()[0].getName();
-            if (!placeHolderName.equals(newBound.getUnresolvedName())) {
-                // we should produce a clean placeholder ClassNode here
-                ClassNode clean = make(placeHolderName);
-                clean.setGenericsTypes(newBound.getGenericsTypes());
-                clean.setRedirect(newBound);
-                newBound = clean;
-            }
-            newBound.setGenericsPlaceHolder(true);
-        }
-        return newBound;
+    static ClassNode[] applyGenericsContext(final Map<GenericsTypeName, GenericsType> spec, final ClassNode[] types) {
+        if (types == null) return null;
+        final int nTypes = types.length;
+        ClassNode[] newTypes = new ClassNode[nTypes];
+        for (int i = 0; i < nTypes; i += 1) {
+            newTypes[i] = applyGenericsContext(spec, types[i]);
+        }
+        return newTypes;
+    }
+
+    static ClassNode applyGenericsContext(final Map<GenericsTypeName, GenericsType> spec, final ClassNode type) {
+        if (type == null || !isUsingGenericsOrIsArrayUsingGenerics(type)) {
+            return type;
+        }
+        if (type.isArray()) {
+            return applyGenericsContext(spec, type.getComponentType()).makeArray();
+        }
+        ClassNode newType = type.getPlainNodeReference();
+        GenericsType[] gt = type.getGenericsTypes();
+        if (asBoolean(spec)) {
+            gt = applyGenericsContext(spec, gt);
+        }
+        newType.setGenericsTypes(gt);
+        if (type.isGenericsPlaceHolder()) {
+            boolean nonTrivial = hasNonTrivialBounds(gt[0]);
+            if (nonTrivial || !gt[0].isPlaceholder()) {
+                return getCombinedBoundType(gt[0]);
+            }
+            String placeholderName = gt[0].getName();
+            if (!placeholderName.equals(newType.getUnresolvedName())) {
+                ClassNode clean = make(placeholderName);
+                clean.setGenericsTypes(gt);
+                clean.setRedirect(newType);
+                newType = clean;
+            }
+            newType.setGenericsPlaceHolder(true);
+        }
+        return newType;
     }
 
     static ClassNode getCombinedBoundType(final GenericsType genericsType) {
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 8e568c7..414247f 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -1371,7 +1371,71 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
               }
             }
             new Element()
-'''
+        '''
+
+        // GROOVY-9822
+        config.with {
+            targetDirectory = File.createTempDir()
+            jointCompilationOptions = [memStub: true]
+        }
+        File parentDir = File.createTempDir()
+        try {
+            def a = new File(parentDir, 'Types.java')
+            a.write '''
+                import java.io.*;
+                import java.util.*;
+
+                // from org.apache.tinkerpop:gremlin-core:3.4.8
+
+                interface TraversalStrategy<S extends TraversalStrategy> extends Serializable, Comparable<Class<? extends TraversalStrategy>> {
+                    interface VerificationStrategy extends TraversalStrategy<VerificationStrategy> {
+                    }
+                }
+                abstract class AbstractTraversalStrategy<S extends TraversalStrategy> implements TraversalStrategy<S> {
+                }
+                abstract // don't want to implement Comparable
+                class ReadOnlyStrategy extends AbstractTraversalStrategy<TraversalStrategy.VerificationStrategy>
+                        implements TraversalStrategy.VerificationStrategy {
+                    static ReadOnlyStrategy instance() { return null; }
+                }
+
+                interface TraversalSource extends Cloneable, AutoCloseable {
+                    default TraversalSource withStrategies(TraversalStrategy... strategies) {
+                        return null;
+                    }
+                }
+                abstract // don't want to implement AutoCloseable
+                class GraphTraversalSource implements TraversalSource {
+                    @Override
+                    public GraphTraversalSource withStrategies(TraversalStrategy... strategies) {
+                        return (GraphTraversalSource) TraversalSource.super.withStrategies(strategies);
+                    }
+                }
+                class Graph {
+                    public <C extends TraversalSource> C traversal(Class<C> c) {
+                        return null;
+                    }
+                    public GraphTraversalSource traversal() {
+                        return null;
+                    }
+                }
+            '''
+            def b = new File(parentDir, 'Script.groovy')
+            b.write '''
+                GraphTraversalSource test(Graph graph) {
+                    def strategy = ReadOnlyStrategy.instance()
+                    graph.traversal().withStrategies(strategy)
+                }
+            '''
+
+            def loader = new GroovyClassLoader(this.class.classLoader)
+            def cu = new JavaAwareCompilationUnit(config, loader)
+            cu.addSources(a, b)
+            cu.compile()
+        } finally {
+            parentDir.deleteDir()
+            config.targetDirectory.deleteDir()
+        }
     }
 
     void testRegressionInConstructorCheck() {