Skip to content

Commit

Permalink
GROOVY-9006
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Oct 20, 2021
1 parent 8dd19b8 commit f4c4abf
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Foo> with Foo
if (leftExpression instanceof ClassExpression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Foo> with Foo
if (leftExpression instanceof ClassExpression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type> with Type
if (leftExpression instanceof ClassExpression) {
left = CLASS_Type.getPlainNodeReference();
Expand Down

0 comments on commit f4c4abf

Please sign in to comment.