From f4c4abfcc38e0349cdcf0d8240ac019f44108d7d Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Tue, 19 Oct 2021 17:28:21 -0500 Subject: [PATCH] GROOVY-9006 --- .../core/tests/xform/TypeCheckedTests.java | 22 +++++++++++++++++++ .../stc/StaticTypeCheckingVisitor.java | 7 +++++- .../stc/StaticTypeCheckingVisitor.java | 7 +++++- .../stc/StaticTypeCheckingVisitor.java | 5 +++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java index 4d35458b2e..005ec60729 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java @@ -1557,6 +1557,28 @@ public void testTypeChecked8984a() { "----------\n"); } + @Test + public void testTypeChecked9006() { + if (Float.parseFloat(System.getProperty("java.specification.version")) > 8) + vmArguments = new String[] {"--add-opens", "java.sql/java.sql=ALL-UNNAMED"}; + + //@formatter:off + String[] sources = { + "Main.groovy", + "import java.sql.Timestamp\n" + + "@groovy.transform.TypeChecked\n" + + "void test(Timestamp timestamp) {\n" + + " if (timestamp != null) {\n" + // Reference to method is ambiguous + " print 'works'\n" + + " }\n" + + "}\n" + + "test(new Timestamp(new Date().getTime()))\n", + }; + //@formatter:on + + runConformTest(sources, "works"); + } + @Test public void testTypeChecked9033() { //@formatter:off diff --git a/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index 9155576a10..2765d0a727 100644 --- a/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -5299,7 +5299,12 @@ protected ClassNode getResultType(ClassNode left, int op, ClassNode right, Binar if (mathResultType != null) { return mathResultType; } - + // GRECLIPSE add -- GROOVY-9006: compare to null for equals overloads + if ("equals".equals(operationName) && (left == UNKNOWN_PARAMETER_TYPE + || right == UNKNOWN_PARAMETER_TYPE)) { + return boolean_TYPE; + } + // GRECLIPSE end // GROOVY-5890 // do not mix Class with Foo if (leftExpression instanceof ClassExpression) { diff --git a/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index f0b20ac005..fea43b0235 100644 --- a/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -4963,7 +4963,12 @@ rightExpression instanceof ListExpression && isEmptyCollection(rightExpression)) if (mathResultType != null) { return mathResultType; } - + // GRECLIPSE add -- GROOVY-9006: compare to null for equals overloads + if ("equals".equals(operationName) && (left == UNKNOWN_PARAMETER_TYPE + || right == UNKNOWN_PARAMETER_TYPE)) { + return boolean_TYPE; + } + // GRECLIPSE end // GROOVY-5890 // do not mix Class with Foo if (leftExpression instanceof ClassExpression) { diff --git a/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index 882da8ede7..4b7b9317bb 100644 --- a/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -4622,6 +4622,11 @@ protected ClassNode getResultType(ClassNode left, final int op, final ClassNode 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 with Type if (leftExpression instanceof ClassExpression) { left = CLASS_Type.getPlainNodeReference();