Skip to content

Commit

Permalink
GROOVY-5502 (pt.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Dec 12, 2021
1 parent f849ff3 commit 0873c66
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,38 @@ public void testTypeChecked5450() {
"----------\n");
}

@Test
public void testTypeChecked5502() {
for (String val : new String[] {"null", "new A()", "new B()", "new C()"/*TODO:, "new Object()"*/}) {
//@formatter:off
String[] sources = {
"Main.groovy",
"class A {\n" +
" void m() {\n" +
" }\n" +
"}\n" +
"class B extends A {\n" +
"}\n" +
"class C extends A {\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"void test(boolean flag) {\n" +
" def var = " + val + "\n" +
" if (flag) {\n" +
" var = new B()\n" +
" } else {\n" +
" var = new C()\n" +
" }\n" +
" var.m()\n" + // Cannot find matching method Object#m()
"}\n" +
"test(true)\n",
};
//@formatter:on

runConformTest(sources);
}
}

@Test
public void testTypeChecked5523() {
//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,12 @@ && isAssignment(enclosingBinaryExpression.getOperation().getType())) {
}
}

/* GRECLIPSE edit -- GROOVY-5502
boolean isEmptyDeclaration = expression instanceof DeclarationExpression && rightExpression instanceof EmptyExpression;
*/
boolean isEmptyDeclaration = (expression instanceof DeclarationExpression
&& (rightExpression instanceof EmptyExpression || rType == UNKNOWN_PARAMETER_TYPE));
// GRECLIPSE end
if (!isEmptyDeclaration && isAssignment(op)) {
if (rightExpression instanceof ConstructorCallExpression) {
inferDiamondType((ConstructorCallExpression) rightExpression, lType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,12 @@ && isAssignment(enclosingBinaryExpression.getOperation().getType())) {
}
}

/* GRECLIPSE edit -- GROOVY-5502
boolean isEmptyDeclaration = (expression instanceof DeclarationExpression && rightExpression instanceof EmptyExpression);
*/
boolean isEmptyDeclaration = (expression instanceof DeclarationExpression
&& (rightExpression instanceof EmptyExpression || rType == UNKNOWN_PARAMETER_TYPE));
// GRECLIPSE end
if (isAssignment(op) && !isEmptyDeclaration) {
if (rightExpression instanceof ConstructorCallExpression) {
inferDiamondType((ConstructorCallExpression) rightExpression, lType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,8 @@ && isAssignment(enclosingBinaryExpression.getOperation().getType())) {
}
}

boolean isEmptyDeclaration = (expression instanceof DeclarationExpression && rightExpression instanceof EmptyExpression);
boolean isEmptyDeclaration = (expression instanceof DeclarationExpression
&& (rightExpression instanceof EmptyExpression || rType == UNKNOWN_PARAMETER_TYPE));
if (!isEmptyDeclaration && isAssignment(op)) {
if (rightExpression instanceof ConstructorCallExpression)
inferDiamondType((ConstructorCallExpression) rightExpression, lType);
Expand Down

0 comments on commit 0873c66

Please sign in to comment.