Skip to content

Commit

Permalink
GROOVY-9953
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Feb 25, 2021
1 parent 625858c commit f15b79e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -953,4 +953,27 @@ public void testTypeChecked9948() {

runConformTest(sources, "true");
}

@Test
public void testTypeChecked9953() {
//@formatter:off
String[] sources = {
"Main.groovy",
"class C {\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"C test(Object x) {\n" +
" if (x instanceof C) {\n" +
" def y = x\n" +
" return y\n" +
" } else {\n" +
" new C()\n" +
" }\n" +
"}\n" +
"new C().with { assert test(it).is(it) }\n",
};
//@formatter:on

runConformTest(sources, "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -872,11 +872,17 @@ public void visitBinaryExpression(final BinaryExpression expression) {
rightExpression.visit(this);
}
ClassNode lType = getType(leftExpression);
/* GRECLIPSE edit -- GROOVY-9953
ClassNode rType = getType(rightExpression);
if (isNullConstant(rightExpression)) {
if (!isPrimitiveType(lType))
rType = UNKNOWN_PARAMETER_TYPE; // primitive types should be ignored as they will result in another failure
}
*/
ClassNode rType = isNullConstant(rightExpression) && !isPrimitiveType(lType)
? UNKNOWN_PARAMETER_TYPE
: getInferredTypeFromTempInfo(rightExpression, getType(rightExpression));
// GRECLIPSE end
BinaryExpression reversedBinaryExpression = binX(rightExpression, expression.getOperation(), leftExpression);
ClassNode resultType = op == KEYWORD_IN
? getResultType(rType, op, lType, reversedBinaryExpression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,11 @@ public void visitBinaryExpression(final BinaryExpression expression) {
ClassNode rType = (isNullConstant(rightExpression) && !isPrimitiveType(lType)
// primitive types should be ignored as they will result in another failure
? UNKNOWN_PARAMETER_TYPE
/* GRECLIPSE edit -- GROOVY-9953
: getType(rightExpression)
*/
: getInferredTypeFromTempInfo(rightExpression, getType(rightExpression))
// GRECLIPSE end
);

BinaryExpression reversedBinaryExpression = binX(rightExpression, expression.getOperation(), leftExpression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,11 @@ public void visitBinaryExpression(final BinaryExpression expression) {
ClassNode rType = (isNullConstant(rightExpression) && !isPrimitiveType(lType)
// primitive types should be ignored as they will result in another failure
? UNKNOWN_PARAMETER_TYPE
/* GRECLIPSE edit -- GROOVY-9953
: getType(rightExpression)
*/
: getInferredTypeFromTempInfo(rightExpression, getType(rightExpression))
// GRECLIPSE end
);

BinaryExpression reversedBinaryExpression = binX(rightExpression, expression.getOperation(), leftExpression);
Expand Down

0 comments on commit f15b79e

Please sign in to comment.