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
commit 7c7a4ec76a7524165fb8612b9c864c1e97bcbcd4 Author: Eric Milles <[email protected]> AuthorDate: Tue Oct 19 19:42:22 2021 -0500 GROOVY-9006: STC: compare to null for types that overload equals Conflicts: src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java --- .../groovy/transform/stc/StaticTypeCheckingVisitor.java | 9 +++++++-- src/test/groovy/transform/stc/BugsSTCTest.groovy | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 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 9e9a3e7a00..3b9eaa531b 100644 --- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -4358,8 +4358,13 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport { return mathResultType; } - // GROOVY-5890 - // do not mix Class<Foo> with Foo + // 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 8d3f2eb097..61d90da3ce 100644 --- a/src/test/groovy/transform/stc/BugsSTCTest.groovy +++ b/src/test/groovy/transform/stc/BugsSTCTest.groovy @@ -715,6 +715,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 '''
