groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sh...@apache.org
Subject [1/2] groovy git commit: GROOVY-8157: Flow typing doesn't work with assignment to a parameter (closes #537)
Date Thu, 11 May 2017 06:39:04 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X b11e8fcf2 -> 50b06f1f1


GROOVY-8157: Flow typing doesn't work with assignment to a parameter (closes #537)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/f435c34b
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/f435c34b
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/f435c34b

Branch: refs/heads/GROOVY_2_4_X
Commit: f435c34b718bbd04ba6ece0304a31c0bec4132cb
Parents: b11e8fc
Author: Shil Sinha <shils@apache.org>
Authored: Sat May 6 04:32:20 2017 -0400
Committer: Shil Sinha <shils@apache.org>
Committed: Thu May 11 02:34:11 2017 -0400

----------------------------------------------------------------------
 .../transform/stc/StaticTypeCheckingVisitor.java      |  4 ++++
 .../groovy/transform/stc/STCAssignmentTest.groovy     | 14 ++++++++++++++
 2 files changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/f435c34b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 8c02c33..09a97e5 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3438,6 +3438,9 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
             if (accessedVariable != null && accessedVariable != exp && accessedVariable
instanceof VariableExpression) {
                 storeType((Expression) accessedVariable, cn);
             }
+            if (accessedVariable instanceof Parameter) {
+                ((Parameter) accessedVariable).putNodeMetaData(StaticTypesMarker.INFERRED_TYPE,
cn);
+            }
             if (var.isClosureSharedVariable() && cn!=null) {
                 List<ClassNode> assignedTypes = typeCheckingContext.closureSharedVariablesAssignmentTypes.get(var);
                 if (assignedTypes == null) {
@@ -4000,6 +4003,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
                     storeType((VariableExpression)exp, type);
                     return type;
                 }
+                return getType((Parameter) variable);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/f435c34b/src/test/groovy/transform/stc/STCAssignmentTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/STCAssignmentTest.groovy b/src/test/groovy/transform/stc/STCAssignmentTest.groovy
index e174289..7b40304 100644
--- a/src/test/groovy/transform/stc/STCAssignmentTest.groovy
+++ b/src/test/groovy/transform/stc/STCAssignmentTest.groovy
@@ -830,5 +830,19 @@ class STCAssignmentTest extends StaticTypeCheckingTestCase {
             assert d.method() == "hello"
         '''
     }
+
+    //GROOVY-8157
+    void testFlowTypingAfterParameterAssignment() {
+        assertScript '''
+            class A {}
+            class B extends A { def bbb() { 42 } }
+
+            def fooParameterAssignment(A a) {
+                a = new B()
+                a.bbb()
+            }
+            assert fooParameterAssignment(null) == 42            
+        '''
+    }
 }
 


Mime
View raw message