groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] 01/02: GROOVY-9077: STC: inferred type of property that resolves to method not always stored
Date Tue, 23 Apr 2019 04:55:02 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 336ec2d88b301c27d1dc8adaf71010ab7b2d2b9a
Author: Paul King <paulk@asert.com.au>
AuthorDate: Mon Apr 22 23:31:24 2019 +1000

    GROOVY-9077: STC: inferred type of property that resolves to method not always stored
---
 .../transform/stc/StaticTypeCheckingVisitor.java   |  3 +-
 .../transform/stc/TypeInferenceSTCTest.groovy      | 48 ++++++++++++++++++----
 2 files changed, 42 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 bc67c5e..749cbef 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1524,6 +1524,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
                     if (getter != null) {
                         ClassNode cn = inferReturnTypeGenerics(current, getter, ArgumentListExpression.EMPTY_ARGUMENTS);
                         storeInferredTypeForPropertyExpression(pexp, cn);
+                        storeTargetMethod(pexp, getter);
                         pexp.removeNodeMetaData(StaticTypesMarker.READONLY_PROPERTY);
                         String delegationData = receiver.getData();
                         if (delegationData != null)
@@ -1588,7 +1589,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
                         }
                         ClassNode cn = inferReturnTypeGenerics(dgmReceiver, getter, ArgumentListExpression.EMPTY_ARGUMENTS);
                         storeInferredTypeForPropertyExpression(pexp, cn);
-
+                        storeTargetMethod(pexp, getter);
                         return true;
                     }
                 }
diff --git a/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
index e9acc12..f570378 100644
--- a/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
@@ -769,14 +769,46 @@ Thing.run()
     // GROOVY-6574
     void testShouldInferPrimitiveBoolean() {
         assertScript '''
-def foo(Boolean o) {
-  @ASTTest(phase=INSTRUCTION_SELECTION,value={
-    assert node.getNodeMetaData(INFERRED_TYPE) == boolean_TYPE
-  })
-  boolean b = o
-  println b
-}
+            def foo(Boolean o) {
+                @ASTTest(phase=INSTRUCTION_SELECTION,value={
+                    assert node.getNodeMetaData(INFERRED_TYPE) == boolean_TYPE
+                })
+                boolean b = o
+                println b
+            }
+        '''
+    }
+
+    // GROOVY-9077
+    void testInferredTypeForPropertyThatResolvesToMethod() {
+        assertScript '''
+            import groovy.transform.*
+            import static org.codehaus.groovy.transform.stc.StaticTypesMarker.DIRECT_METHOD_CALL_TARGET
+
+            @CompileStatic
+            void meth() {
+                def items = [1, 2] as LinkedList
+
+                @ASTTest(phase=INSTRUCTION_SELECTION, value={
+                    node = node.rightExpression
+                    assert node.class.name.contains('PropertyExpression')
+                    def target = node.getNodeMetaData(DIRECT_METHOD_CALL_TARGET)
+                    assert target != null
+                    assert target.declaringClass.name == 'java.util.LinkedList'
+                })
+                def one = items.first
+
+                @ASTTest(phase=CLASS_GENERATION, value={
+                    node = node.rightExpression
+                    assert node.class.name.contains('MethodCallExpression')
+                    def target = node.getNodeMetaData(DIRECT_METHOD_CALL_TARGET)
+                    assert target != null
+                    assert target.declaringClass.name == 'java.util.LinkedList'
+                })
+                def alsoOne = items.peek()
+            }
+
+            meth()
 '''
     }
 }
-


Mime
View raw message