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/03/09 18:52:38 UTC

[groovy] branch GROOVY-9454 created (now 375dfbd)

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

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


      at 375dfbd  GROOVY-9454: STC: check for instanceof type before using the field type

This branch includes the following new commits:

     new 375dfbd  GROOVY-9454: STC: check for instanceof type before using the field type

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.



[groovy] 01/01: GROOVY-9454: STC: check for instanceof type before using the field type

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

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

commit 375dfbd803073b4711154059001f913a8e7d7a4e
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Mar 9 13:52:23 2020 -0500

    GROOVY-9454: STC: check for instanceof type before using the field type
---
 .../transform/stc/StaticTypeCheckingVisitor.java   | 22 ++++++++++++++--------
 .../transform/stc/TypeInferenceSTCTest.groovy      |  3 +--
 2 files changed, 15 insertions(+), 10 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 e41f14b..08a07c5 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -604,14 +604,20 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
             if (enclosingClosure != null) {
                 tryVariableExpressionAsProperty(vexp, name);
             } else {
-                // GROOVY-7691
-                FieldNode fieldNode = (FieldNode) accessedVariable;
-                ClassNode actualType = findActualTypeByGenericsPlaceholderName(
-                        fieldNode.getOriginType().getUnresolvedName(),
-                        makeDeclaringAndActualGenericsTypeMapOfExactType(fieldNode.getDeclaringClass(), typeCheckingContext.getEnclosingClassNode())
-                );
-                if (actualType != null) {
-                    storeType(vexp, actualType);
+                // GROOVY-9454
+                ClassNode inferredType = getInferredTypeFromTempInfo(vexp, null);
+                if (inferredType != null && !inferredType.equals(OBJECT_TYPE)) {
+                    vexp.putNodeMetaData(INFERRED_RETURN_TYPE, inferredType);
+                } else {
+                    // GROOVY-7691
+                    FieldNode fieldNode = (FieldNode) accessedVariable;
+                    ClassNode fieldType = findActualTypeByGenericsPlaceholderName(
+                            fieldNode.getOriginType().getUnresolvedName(),
+                            makeDeclaringAndActualGenericsTypeMapOfExactType(fieldNode.getDeclaringClass(), typeCheckingContext.getEnclosingClassNode())
+                    );
+                    if (fieldType != null) {
+                        storeType(vexp, fieldType);
+                    }
                 }
             }
         } else if (accessedVariable instanceof PropertyNode) {
diff --git a/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
index 2562166..3813e75 100644
--- a/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
@@ -18,7 +18,6 @@
  */
 package groovy.transform.stc
 
-import groovy.test.NotYetImplemented
 import org.codehaus.groovy.ast.ClassHelper
 import org.codehaus.groovy.ast.ClassNode
 import org.codehaus.groovy.ast.MethodNode
@@ -142,7 +141,7 @@ class TypeInferenceSTCTest extends StaticTypeCheckingTestCase {
         ''', 'Cannot find matching method java.lang.Object#toUpperCase()'
     }
 
-    @NotYetImplemented // GROOVY-9454
+    // GROOVY-9454
     void testInstanceOfOnGenericProperty() {
         assertScript '''
             interface Face {