diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java index 95f8291ea9..228dabd6dc 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java @@ -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, ""); + } } diff --git a/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index 9b32192a0e..37db272a47 100644 --- a/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -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) diff --git a/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index af4c79f766..1694aeb8bc 100644 --- a/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -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); diff --git a/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index 9acd096296..d4ef06fdd3 100644 --- a/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -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);