Quantcast

[1/2] groovy git commit: GROOVY-8157: Flow typing doesn't work with assignment to a parameter (closes #537)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[1/2] groovy git commit: GROOVY-8157: Flow typing doesn't work with assignment to a parameter (closes #537)

shils-2
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 378540a37 -> 946eadb9c


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/8bd2e44f
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/8bd2e44f
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/8bd2e44f

Branch: refs/heads/GROOVY_2_5_X
Commit: 8bd2e44f10e7183d245151c273c2bc7d6adfd005
Parents: 378540a
Author: Shil Sinha <[hidden email]>
Authored: Sat May 6 04:32:20 2017 -0400
Committer: Shil Sinha <[hidden email]>
Committed: Thu May 11 02:26:02 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/8bd2e44f/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 8a08e58..345879e 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3459,6 +3459,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) {
@@ -4024,6 +4027,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/8bd2e44f/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            
+        '''
+    }
 }
 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[2/2] groovy git commit: GROOVY-8074: Statically compiled dot property accesses instance property instead of Map property (closes #539)

shils-2
GROOVY-8074: Statically compiled dot property accesses instance property instead of Map property (closes #539)


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

Branch: refs/heads/GROOVY_2_5_X
Commit: 946eadb9c4115daca3a382816f3aa42a4a1c7005
Parents: 8bd2e44
Author: Shil Sinha <[hidden email]>
Authored: Sun May 7 14:47:19 2017 -0400
Committer: Shil Sinha <[hidden email]>
Committed: Thu May 11 02:26:09 2017 -0400

----------------------------------------------------------------------
 .../asm/sc/StaticTypesCallSiteWriter.java       | 26 +++++++++-----------
 ...ArraysAndCollectionsStaticCompileTest.groovy | 12 +++++++++
 2 files changed, 24 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/946eadb9/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
index 727739d..02203ad 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
@@ -137,6 +137,15 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
             expr.visit(controller.getAcg());
             return;
         }
+
+        boolean isStaticProperty = receiver instanceof ClassExpression
+                && (receiverType.isDerivedFrom(receiver.getType()) || receiverType.implementsInterface(receiver.getType()));
+
+        if (!isStaticProperty && (receiverType.implementsInterface(MAP_TYPE) || MAP_TYPE.equals(receiverType))) {
+            // for maps, replace map.foo with map.get('foo')
+            writeMapDotProperty(receiver, methodName, mv, safe);
+            return;
+        }
         if (makeGetPropertyWithGetter(receiver, receiverType, methodName, safe, implicitThis)) return;
         if (makeGetField(receiver, receiverType, methodName, safe, implicitThis, samePackages(receiverType.getPackageName(), classNode.getPackageName()))) return;
         if (receiverType.isEnum()) {
@@ -211,22 +220,11 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
             }
         }
 
-        boolean isStaticProperty = receiver instanceof ClassExpression
-                && (receiverType.isDerivedFrom(receiver.getType()) || receiverType.implementsInterface(receiver.getType()));
-
-        if (!isStaticProperty) {
-            if (receiverType.implementsInterface(MAP_TYPE) || MAP_TYPE.equals(receiverType)) {
-                // for maps, replace map.foo with map.get('foo')
-                writeMapDotProperty(receiver, methodName, mv, safe);
-                return;
-            }
-            if (receiverType.implementsInterface(LIST_TYPE) || LIST_TYPE.equals(receiverType)) {
-                writeListDotProperty(receiver, methodName, mv, safe);
-                return;
-            }
+        if (!isStaticProperty && (receiverType.implementsInterface(LIST_TYPE) || LIST_TYPE.equals(receiverType))) {
+            writeListDotProperty(receiver, methodName, mv, safe);
+            return;
         }
 
-
         controller.getSourceUnit().addError(
                 new SyntaxException("Access to "+
                                                 (receiver instanceof ClassExpression ?receiver.getType():receiverType).toString(false)

http://git-wip-us.apache.org/repos/asf/groovy/blob/946eadb9/src/test/org/codehaus/groovy/classgen/asm/sc/ArraysAndCollectionsStaticCompileTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/ArraysAndCollectionsStaticCompileTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/ArraysAndCollectionsStaticCompileTest.groovy
index fbb4f3c..3e6f278 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/ArraysAndCollectionsStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/ArraysAndCollectionsStaticCompileTest.groovy
@@ -128,6 +128,18 @@ class ArraysAndCollectionsStaticCompileTest extends ArraysAndCollectionsSTCTest
         }
     }
 
+    void testMapSubclassPropertyStyleAccess() {
+        assertScript '''
+            class MyMap extends LinkedHashMap {
+                def foo = 1
+            }
+        
+            def map = new MyMap()
+            map.put('foo', 42)
+            assert map.foo == 42              
+        '''
+    }
+
     @Override
     void testForInLoop() {
         try {

Loading...