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 2021/10/20 00:59:25 UTC
[groovy] branch GROOVY-9006 created (now 8651402)
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a change to branch GROOVY-9006
in repository https://gitbox.apache.org/repos/asf/groovy.git.
at 8651402 GROOVY-9006: STC: compare to null for types that overload equals
This branch includes the following new commits:
new 8651402 GROOVY-9006: STC: compare to null for types that overload equals
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-9006: STC: compare to null for types that
overload equals
Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY-9006
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 8651402c5a75811c5fd93519bb97f899d4415ce2
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Oct 19 19:42:22 2021 -0500
GROOVY-9006: STC: compare to null for types that overload equals
---
.../groovy/transform/stc/StaticTypeCheckingVisitor.java | 5 +++++
src/test/groovy/transform/stc/BugsSTCTest.groovy | 15 +++++++++++++++
2 files changed, 20 insertions(+)
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 9c2ce3d..ca9f9ad 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -4474,6 +4474,11 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
if (mathResultType != null) {
return mathResultType;
}
+ // GROOVY-9006: compare to null for types that overload equals
+ if ("equals".equals(operationName) && (left == UNKNOWN_PARAMETER_TYPE
+ || right == UNKNOWN_PARAMETER_TYPE)) {
+ return boolean_TYPE;
+ }
// GROOVY-5890: do not mix Class<Type> with Type
if (leftExpression instanceof ClassExpression) {
left = CLASS_Type.getPlainNodeReference();
diff --git a/src/test/groovy/transform/stc/BugsSTCTest.groovy b/src/test/groovy/transform/stc/BugsSTCTest.groovy
index 0781a77..5837086 100644
--- a/src/test/groovy/transform/stc/BugsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/BugsSTCTest.groovy
@@ -788,6 +788,21 @@ Printer
'''
}
+ // GROOVY-9006
+ void testAmbiguousMethodResolutionTimestampComparedToNull() {
+ assertScript '''
+ import java.sql.Timestamp
+
+ def test(Timestamp timestamp) {
+ if (timestamp != null) { // Reference to method is ambiguous
+ return 'not null'
+ }
+ }
+ def result = test(new Timestamp(new Date().getTime()))
+ assert result == 'not null'
+ '''
+ }
+
// GROOVY-6911
void testShouldNotThrowArrayIndexOfOutBoundsException() {
assertScript '''