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 2023/04/10 22:11:14 UTC
[groovy] branch GROOVY_3_0_X updated: GROOVY-11007: STC: property as variable expression keeps temporary types
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
new 925974494e GROOVY-11007: STC: property as variable expression keeps temporary types
925974494e is described below
commit 925974494e880ee1171636328f7950608dc7bb7c
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Apr 10 16:19:27 2023 -0500
GROOVY-11007: STC: property as variable expression keeps temporary types
---
.../transform/stc/StaticTypeCheckingVisitor.java | 9 +++++----
.../transform/stc/TypeInferenceSTCTest.groovy | 22 ++++++++++++++++++++++
2 files changed, 27 insertions(+), 4 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 46bf78d79c..697ed358b7 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -680,11 +680,12 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
Object val = pexp.getNodeMetaData(key);
if (val != null) vexp.putNodeMetaData(key, val);
}
- vexp.removeNodeMetaData(INFERRED_TYPE);
- if (!asBoolean(getTemporaryTypesForExpression(vexp))) {
- ClassNode type = pexp.getNodeMetaData(INFERRED_TYPE);
- storeType(vexp, Optional.ofNullable(type).orElseGet(pexp::getType));
+ ClassNode type = pexp.getNodeMetaData(INFERRED_TYPE);
+ if (vexp.isClosureSharedVariable()) {
+ type = wrapTypeIfNecessary(type);
}
+ if (type == null) type = OBJECT_TYPE;
+ vexp.putNodeMetaData(INFERRED_TYPE, type); // GROOVY-11007
String receiver = vexp.getNodeMetaData(IMPLICIT_RECEIVER);
Boolean dynamic = pexp.getNodeMetaData(DYNAMIC_RESOLUTION);
// GROOVY-7701, GROOVY-7996: correct false assumption made by VariableScopeVisitor
diff --git a/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
index fca9832ad2..ca5106eede 100644
--- a/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
@@ -260,6 +260,28 @@ class TypeInferenceSTCTest extends StaticTypeCheckingTestCase {
'Cannot return value of type Foo for method returning Bar'
}
+ // GROOVY-11007
+ void testInstanceOf11() {
+ assertScript '''
+ interface I {
+ CharSequence getCharSequence()
+ }
+
+ void accept(CharSequence cs) { }
+
+ void test(I i) {
+ i.with {
+ if (charSequence instanceof String) {
+ charSequence.toUpperCase()
+ accept(charSequence)
+ }
+ }
+ }
+
+ test({ -> 'works' } as I)
+ '''
+ }
+
void testNestedInstanceOf1() {
assertScript '''
Object o