Skip to content

Commit f15b79e

Browse files
committed
GROOVY-9953
1 parent 625858c commit f15b79e

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

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

+23
Original file line numberDiff line numberDiff line change
@@ -953,4 +953,27 @@ public void testTypeChecked9948() {
953953

954954
runConformTest(sources, "true");
955955
}
956+
957+
@Test
958+
public void testTypeChecked9953() {
959+
//@formatter:off
960+
String[] sources = {
961+
"Main.groovy",
962+
"class C {\n" +
963+
"}\n" +
964+
"@groovy.transform.TypeChecked\n" +
965+
"C test(Object x) {\n" +
966+
" if (x instanceof C) {\n" +
967+
" def y = x\n" +
968+
" return y\n" +
969+
" } else {\n" +
970+
" new C()\n" +
971+
" }\n" +
972+
"}\n" +
973+
"new C().with { assert test(it).is(it) }\n",
974+
};
975+
//@formatter:on
976+
977+
runConformTest(sources, "");
978+
}
956979
}

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

+6
Original file line numberDiff line numberDiff line change
@@ -872,11 +872,17 @@ public void visitBinaryExpression(final BinaryExpression expression) {
872872
rightExpression.visit(this);
873873
}
874874
ClassNode lType = getType(leftExpression);
875+
/* GRECLIPSE edit -- GROOVY-9953
875876
ClassNode rType = getType(rightExpression);
876877
if (isNullConstant(rightExpression)) {
877878
if (!isPrimitiveType(lType))
878879
rType = UNKNOWN_PARAMETER_TYPE; // primitive types should be ignored as they will result in another failure
879880
}
881+
*/
882+
ClassNode rType = isNullConstant(rightExpression) && !isPrimitiveType(lType)
883+
? UNKNOWN_PARAMETER_TYPE
884+
: getInferredTypeFromTempInfo(rightExpression, getType(rightExpression));
885+
// GRECLIPSE end
880886
BinaryExpression reversedBinaryExpression = binX(rightExpression, expression.getOperation(), leftExpression);
881887
ClassNode resultType = op == KEYWORD_IN
882888
? getResultType(rType, op, lType, reversedBinaryExpression)

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

+4
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,11 @@ public void visitBinaryExpression(final BinaryExpression expression) {
786786
ClassNode rType = (isNullConstant(rightExpression) && !isPrimitiveType(lType)
787787
// primitive types should be ignored as they will result in another failure
788788
? UNKNOWN_PARAMETER_TYPE
789+
/* GRECLIPSE edit -- GROOVY-9953
789790
: getType(rightExpression)
791+
*/
792+
: getInferredTypeFromTempInfo(rightExpression, getType(rightExpression))
793+
// GRECLIPSE end
790794
);
791795

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

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

+4
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,11 @@ public void visitBinaryExpression(final BinaryExpression expression) {
786786
ClassNode rType = (isNullConstant(rightExpression) && !isPrimitiveType(lType)
787787
// primitive types should be ignored as they will result in another failure
788788
? UNKNOWN_PARAMETER_TYPE
789+
/* GRECLIPSE edit -- GROOVY-9953
789790
: getType(rightExpression)
791+
*/
792+
: getInferredTypeFromTempInfo(rightExpression, getType(rightExpression))
793+
// GRECLIPSE end
790794
);
791795

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

0 commit comments

Comments
 (0)