This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new e7e057f4ba GROOVY-11007: STC: property as variable expression keeps
temporary types
e7e057f4ba is described below
commit e7e057f4ba4a3bfa617d9770f8d364ab40b4108b
Author: Eric Milles <[email protected]>
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 3f35b6db1d..acfc961488 100644
---
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -744,11 +744,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 ca81b988b6..b8d3478e28 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