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 2022/08/26 20:07:37 UTC
[groovy] branch GROOVY_2_5_X updated: GROOVY-9953: STC: consider `instanceof` flow-type for binary expr RHS
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
new cd4114ca5b GROOVY-9953: STC: consider `instanceof` flow-type for binary expr RHS
cd4114ca5b is described below
commit cd4114ca5b48f6317bbe8298dbb4fb17741c4e5d
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Aug 26 14:47:01 2022 -0500
GROOVY-9953: STC: consider `instanceof` flow-type for binary expr RHS
---
.../groovy/transform/stc/StaticTypeCheckingVisitor.java | 4 ++--
src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy | 13 +++++++------
2 files changed, 9 insertions(+), 8 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 e3e0ef77cf..8d5a22d902 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -804,8 +804,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
}
rType = isNullConstant(rightExpression) && !isPrimitiveType(lType)
- ? UNKNOWN_PARAMETER_TYPE
- : getType(rightExpression);
+ ? UNKNOWN_PARAMETER_TYPE // null to primitive type is handled elsewhere
+ : getInferredTypeFromTempInfo(rightExpression, getType(rightExpression)); // GROOVY-9953
BinaryExpression reversedBinaryExpression = binX(rightExpression, expression.getOperation(), leftExpression);
ClassNode resultType = op == KEYWORD_IN
? getResultType(rType, op, lType, reversedBinaryExpression)
diff --git a/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
index 1cf3081463..a639a7ac75 100644
--- a/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy
@@ -159,20 +159,21 @@ class TypeInferenceSTCTest extends StaticTypeCheckingTestCase {
'''
}
- @NotYetImplemented // GROOVY-9953
+ // GROOVY-9953
void testInstanceOf6() {
assertScript '''
- class A {
+ class C {
}
- A test(Object x) {
- if (x instanceof A) {
+ C test(Object x) {
+ if (x instanceof C) {
def y = x
return y
} else {
- new A()
+ new C()
}
}
- new A().with { assert test(it) === it }
+ def c = new C()
+ assert test(c).is(c)
'''
}