Skip to content

Commit f4c4abf

Browse files
committed
GROOVY-9006
1 parent 8dd19b8 commit f4c4abf

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java

+22
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,28 @@ public void testTypeChecked8984a() {
15571557
"----------\n");
15581558
}
15591559

1560+
@Test
1561+
public void testTypeChecked9006() {
1562+
if (Float.parseFloat(System.getProperty("java.specification.version")) > 8)
1563+
vmArguments = new String[] {"--add-opens", "java.sql/java.sql=ALL-UNNAMED"};
1564+
1565+
//@formatter:off
1566+
String[] sources = {
1567+
"Main.groovy",
1568+
"import java.sql.Timestamp\n" +
1569+
"@groovy.transform.TypeChecked\n" +
1570+
"void test(Timestamp timestamp) {\n" +
1571+
" if (timestamp != null) {\n" + // Reference to method is ambiguous
1572+
" print 'works'\n" +
1573+
" }\n" +
1574+
"}\n" +
1575+
"test(new Timestamp(new Date().getTime()))\n",
1576+
};
1577+
//@formatter:on
1578+
1579+
runConformTest(sources, "works");
1580+
}
1581+
15601582
@Test
15611583
public void testTypeChecked9033() {
15621584
//@formatter:off

base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -5299,7 +5299,12 @@ protected ClassNode getResultType(ClassNode left, int op, ClassNode right, Binar
52995299
if (mathResultType != null) {
53005300
return mathResultType;
53015301
}
5302-
5302+
// GRECLIPSE add -- GROOVY-9006: compare to null for equals overloads
5303+
if ("equals".equals(operationName) && (left == UNKNOWN_PARAMETER_TYPE
5304+
|| right == UNKNOWN_PARAMETER_TYPE)) {
5305+
return boolean_TYPE;
5306+
}
5307+
// GRECLIPSE end
53035308
// GROOVY-5890
53045309
// do not mix Class<Foo> with Foo
53055310
if (leftExpression instanceof ClassExpression) {

base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -4963,7 +4963,12 @@ rightExpression instanceof ListExpression && isEmptyCollection(rightExpression))
49634963
if (mathResultType != null) {
49644964
return mathResultType;
49654965
}
4966-
4966+
// GRECLIPSE add -- GROOVY-9006: compare to null for equals overloads
4967+
if ("equals".equals(operationName) && (left == UNKNOWN_PARAMETER_TYPE
4968+
|| right == UNKNOWN_PARAMETER_TYPE)) {
4969+
return boolean_TYPE;
4970+
}
4971+
// GRECLIPSE end
49674972
// GROOVY-5890
49684973
// do not mix Class<Foo> with Foo
49694974
if (leftExpression instanceof ClassExpression) {

base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+5
Original file line numberDiff line numberDiff line change
@@ -4622,6 +4622,11 @@ protected ClassNode getResultType(ClassNode left, final int op, final ClassNode
46224622
if (mathResultType != null) {
46234623
return mathResultType;
46244624
}
4625+
// GROOVY-9006: compare to null for types that overload equals
4626+
if ("equals".equals(operationName) && (left == UNKNOWN_PARAMETER_TYPE
4627+
|| right == UNKNOWN_PARAMETER_TYPE)) {
4628+
return boolean_TYPE;
4629+
}
46254630
// GROOVY-5890: do not mix Class<Type> with Type
46264631
if (leftExpression instanceof ClassExpression) {
46274632
left = CLASS_Type.getPlainNodeReference();

0 commit comments

Comments
 (0)