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 2020/06/14 13:46:36 UTC

[groovy] branch GROOVY-9516 updated (1d21c3d -> b1cb54e)

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

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


    omit 1d21c3d  GROOVY-9344, GROOVY-9516: track assign in closure like if/else branch
     new b1cb54e  GROOVY-9344, GROOVY-9516: track assign in closure like if/else branch

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   (1d21c3d)
            \
             N -- N -- N   refs/heads/GROOVY-9516 (b1cb54e)

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:
 src/test/groovy/transform/stc/ClosuresSTCTest.groovy | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[groovy] 01/01: GROOVY-9344, GROOVY-9516: track assign in closure like if/else branch

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

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

commit b1cb54e17a2a93d048f49bca32e2e233891dc01c
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Jun 14 07:51:15 2020 -0500

    GROOVY-9344, GROOVY-9516: track assign in closure like if/else branch
---
 .../transform/stc/StaticTypeCheckingVisitor.java       |  3 +++
 src/test/groovy/transform/stc/ClosuresSTCTest.groovy   | 18 +++++++++++++++++-
 .../classgen/asm/sc/StaticCompileFlowTypingTest.groovy | 15 +++++++--------
 3 files changed, 27 insertions(+), 9 deletions(-)

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 f5485fa..723965c 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2392,6 +2392,9 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
         if (typesBeforeVisit != null) {
             for (Map.Entry<VariableExpression, Map<StaticTypesMarker, Object>> entry : typesBeforeVisit.entrySet()) {
                 for (StaticTypesMarker marker : StaticTypesMarker.values()) {
+                    // GROOVY-9344, GROOVY-9516
+                    if (marker == INFERRED_TYPE) continue;
+
                     Object value = entry.getValue().get(marker);
                     if (value == null) {
                         entry.getKey().removeNodeMetaData(marker);
diff --git a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
index 11ce461..3eb1502 100644
--- a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
@@ -168,7 +168,23 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
             def x = '123';
             { -> x = 123 }
             x.charAt(0) // available in String but not available in Integer
-        ''', 'A closure shared variable [x] has been assigned with various types and the method [charAt(int)] does not exist in the lowest upper bound'
+        ''', 'Cannot find matching method java.io.Serializable or java.lang.Comparable'
+    }
+
+    // GROOVY-9516
+    void testClosureSharedVariable3() {
+        shouldFailWithMessages '''
+            class A {}
+            class B extends A { def m() {} }
+            class C extends A {}
+
+            void test() {
+              def x = new B();
+              { -> x = new C() }();
+              def c = x
+              c.m()
+            }
+        ''', 'Cannot find matching method A#m()'
     }
 
     void testClosureCallAsAMethod() {
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/StaticCompileFlowTypingTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/StaticCompileFlowTypingTest.groovy
index 86632f8..4b48fe4 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/StaticCompileFlowTypingTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/StaticCompileFlowTypingTest.groovy
@@ -18,7 +18,6 @@
  */
 package org.codehaus.groovy.classgen.asm.sc
 
-import groovy.test.NotYetImplemented
 import groovy.transform.CompileStatic
 import org.junit.Test
 
@@ -51,10 +50,10 @@ final class StaticCompileFlowTypingTest {
 
             @groovy.transform.CompileStatic
             String m() {
-                def var = new A()
+                def x = new A()
                 def c = { ->
-                    var = new B()
-                    var.class.simpleName
+                    x = new B()
+                    x.class.simpleName
                 }
                 c()
             }
@@ -62,7 +61,7 @@ final class StaticCompileFlowTypingTest {
         '''
     }
 
-    @NotYetImplemented @Test // GROOVY-9344
+    @Test // GROOVY-9344
     void testFlowTyping3() {
         assertScript '''
             class A {}
@@ -70,12 +69,12 @@ final class StaticCompileFlowTypingTest {
 
             @groovy.transform.CompileStatic
             String m() {
-                def var = new A()
+                def x = new A()
                 def c = { ->
-                    var = new B()
+                    x = new B()
                 }
                 c()
-                var.class.simpleName
+                x.class.simpleName
             }
             assert m() == 'B'
         '''