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/12/19 14:19:36 UTC

[groovy] branch GROOVY-10300 updated (faeffc7 -> 3831eb2)

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

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


 discard faeffc7  GROOVY-10300: resolve script source
     new 3831eb2  GROOVY-10300: resolve script source

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (faeffc7)
            \
             N -- N -- N   refs/heads/GROOVY-10300 (3831eb2)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 .../codehaus/groovy/control/CompilationUnit.java   | 11 +++--
 .../codehaus/groovy/control/ResolveVisitor.java    | 17 ++++----
 .../groovy/bugs/groovy9243/Main.groovy             | 49 +++++++++++++---------
 3 files changed, 45 insertions(+), 32 deletions(-)

[groovy] 01/01: GROOVY-10300: resolve script source

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

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

commit 3831eb20b0bf183af9fac6ea036196d91a03880e
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Dec 15 12:37:22 2021 -0600

    GROOVY-10300: resolve script source
---
 .../codehaus/groovy/control/CompilationUnit.java   |  9 ++--
 .../codehaus/groovy/control/ResolveVisitor.java    | 10 +++++
 .../groovy/bugs/groovy7812/MainWithErrors.groovy   | 22 ----------
 .../groovy/bugs/groovy9243/Main.groovy             | 49 +++++++++++++---------
 src/test/groovy/script/RuntimeResolveTests.groovy  | 29 ++++---------
 5 files changed, 55 insertions(+), 64 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/control/CompilationUnit.java b/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
index 52a8379..dfc9a84 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
@@ -624,8 +624,13 @@ public class CompilationUnit extends ProcessingUnit {
                         ? sources.values().parallelStream() : sources.values().stream()
                 ).forEach(SourceUnit::buildAST);
             }
+            try {
+                processPhaseOperations(phase);
+            } catch (ResolveVisitor.Interrupt x) {
+                assert !queuedSources.isEmpty();
+            }
+            if (dequeued()) continue; // bring new sources into phase
 
-            processPhaseOperations(phase);
             // Grab processing may have brought in new AST transforms into various phases, process them as well
             processNewPhaseOperations(phase);
 
@@ -634,8 +639,6 @@ public class CompilationUnit extends ProcessingUnit {
             completePhase();
             mark();
 
-            if (dequeued()) continue; // bring new sources into phase
-
             gotoPhase(phase + 1);
 
             if (phase == Phases.CLASS_GENERATION) {
diff --git a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
index 7ab7359..ff6c84e 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -239,6 +239,15 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
         }
     }
 
+    @SuppressWarnings("serial")
+    static class Interrupt extends CompilationFailedException {
+        private Interrupt(final ProcessingUnit unit) {
+            super(Phases.SEMANTIC_ANALYSIS, unit);
+        }
+    }
+
+    //--------------------------------------------------------------------------
+
     public ResolveVisitor(final CompilationUnit compilationUnit) {
         this.compilationUnit = compilationUnit;
         // TODO: CompilationUnit.ClassNodeResolver?
@@ -762,6 +771,7 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
             if (lr != null) {
                 if (lr.isSourceUnit()) {
                     currentClass.getCompileUnit().addClassNodeToCompile(type, lr.getSourceUnit());
+                    throw new Interrupt(compilationUnit); // GROOVY-10300, et al.: restart resolve
                 } else {
                     type.setRedirect(lr.getClassNode());
                 }
diff --git a/src/test-resources/groovy/bugs/groovy7812/MainWithErrors.groovy b/src/test-resources/groovy/bugs/groovy7812/MainWithErrors.groovy
deleted file mode 100644
index 091a59e..0000000
--- a/src/test-resources/groovy/bugs/groovy7812/MainWithErrors.groovy
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- *  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.groovy7812
-
-assert new Outer()
-assert new Outer.Inner123()
diff --git a/src/test-resources/groovy/bugs/groovy9243/Main.groovy b/src/test-resources/groovy/bugs/groovy9243/Main.groovy
index 72b8d47..dfbb289 100644
--- a/src/test-resources/groovy/bugs/groovy9243/Main.groovy
+++ b/src/test-resources/groovy/bugs/groovy9243/Main.groovy
@@ -18,32 +18,43 @@
  */
 package groovy.bugs.groovy9243
 
-class Groovy9243 extends Base {
-    def accessX() {
-        assert 'staticClassX' == new X().name
+final class Groovy9243 extends Base {
+    def accessX1() {
+        String name = new X().name
+        assert name =='staticClassX'
     }
-    def accessBaseX() {
-        assert 'staticClassX' == new Base.X().name
+    def accessX2() {
+        String name = new Base.X().name
+        assert name == 'staticClassX'
     }
-    def accessBaseX2() {
-        assert 'staticClassX' == new groovy.bugs.groovy9243.Base.X().name
+    def accessX3() {
+        String name = new groovy.bugs.groovy9243.Base.X().name
+        assert name == 'staticClassX'
     }
-    def accessY() {
-        assert 'classY' == this.new Y().name
+    def accessY1() {
+        String name = new Y().name
+        assert name == 'classY'
     }
     def accessY2() {
-        def g = new Groovy9243()
-        assert 'classY' == g.new Y().name
+        String name = this.new Y().name
+        assert name == 'classY'
     }
     def accessY3() {
-        assert 'classY' == new Groovy9243().new Y().name
+        def that = new Groovy9243()
+        String name = that.new Y().name
+        assert name == 'classY'
     }
+    /*def accessY4() {
+        String name = new Groovy9243().new Y().name
+        assert name == 'classY'
+    }*/
 }
 
-def g = new Groovy9243()
-g.accessX()
-g.accessBaseX()
-g.accessBaseX2()
-g.accessY()
-g.accessY2()
-g.accessY3()
+new Groovy9243().with {
+    accessX1()
+    accessX2()
+    accessX3()
+    accessY1()
+    accessY2()
+    accessY3()
+}
diff --git a/src/test/groovy/script/RuntimeResolveTests.groovy b/src/test/groovy/script/RuntimeResolveTests.groovy
index c8e6303..d5893f0 100644
--- a/src/test/groovy/script/RuntimeResolveTests.groovy
+++ b/src/test/groovy/script/RuntimeResolveTests.groovy
@@ -18,65 +18,54 @@
  */
 package groovy.script
 
-import org.junit.Ignore
 import org.junit.Test
 
 import static org.apache.groovy.util.ScriptRunner.runScript
 
-@Ignore('disabled pending rework')
 final class RuntimeResolveTests {
 
     @Test
-    void testResolveOuterStaticNestedClass() {
+    void testResolveStaticImportOfOuterMember1() {
         runScript('/groovy/bugs/groovy4287/Main.groovy')
     }
 
     @Test
-    void testResolveOuterStaticNestedClassAlias() {
+    void testResolveStaticImportOfOuterMember2() {
         runScript('/groovy/bugs/groovy4287/Main2.groovy')
     }
 
     @Test
-    void testResolvePublicStaticField() {
+    void testResolveStaticImportOfOuterMember3() {
         runScript('/groovy/bugs/groovy4386/StaticField.groovy')
     }
 
     @Test
-    void testResolveStaticProperty() {
+    void testResolveStaticImportOfOuterMember4() {
         runScript('/groovy/bugs/groovy4386/StaticProperty.groovy')
     }
 
     @Test
-    void testResolveStaticMembers() {
+    void testResolveStaticImportOfOuterMember5() {
         runScript('/groovy/bugs/groovy4386/StaticStarImport.groovy')
     }
 
     @Test
-    void testResolveOuterNestedClass() {
+    void testResolveOuterMemberWithoutAnImport() {
         runScript('/groovy/bugs/groovy7812/Main.groovy')
     }
 
-    @Test @Ignore('exception in script causes problem for build')
-    void testUnresolvableInnerClass() {
-        try {
-            runScript('/groovy/bugs/groovy7812/MainWithErrors.groovy')
-        } catch (Throwable t) {
-            assert t.getMessage().contains('unable to resolve class Outer.Inner123')
-        }
-    }
-
     @Test
-    void testResolvePrecedence() {
+    void testResolvePackagePeerWithoutAnImport() {
         runScript('/groovy/bugs/groovy9236/Main.groovy')
     }
 
     @Test
-    void testResolveNestedClassFromBaseType() {
+    void testResolveOuterMemberWithoutAnImport2() {
         runScript('/groovy/bugs/groovy9243/Main.groovy')
     }
 
     @Test
-    void testTraitSuperFromOverriddenMethod() {
+    void testResolvePackagePeersAndCompileTrait() {
         runScript('/groovy/bugs/groovyA144/Main.groovy')
     }
 }