diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java index 1dd3020ab3c..161a5adc12f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java @@ -665,6 +665,8 @@ public class CandidateResolver { DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue( JetPsiUtil.unwrapFromBlock(argumentExpression), type, trace.getBindingContext()); + if (!dataFlowValue.isStableIdentifier()) return type; + Set possibleTypes = dataFlowInfoForArgument.getPossibleTypes(dataFlowValue); if (possibleTypes.isEmpty()) return type; diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/kt4009.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/kt4009.kt new file mode 100644 index 00000000000..6fef9f3402e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/kt4009.kt @@ -0,0 +1,21 @@ +trait PsiElement { + fun getText(): String + fun getParent(): PsiElement +} + +trait JetExpression : PsiElement + +fun foo1(e: PsiElement) { + var current: PsiElement? = e + var first = true + while (current != null) { + if (current is JetExpression && first) { + println(current!!.getText()) // error: smart cast not possible. But it's not needed in fact! + } + + current = current?.getParent() + } +} + +//from library +fun println(any: Any?) = throw Exception("$any") \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 994b7a62c75..747a6dbf332 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -5608,6 +5608,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/smartCasts/inference/kt2851.kt"); } + @TestMetadata("kt4009.kt") + public void testKt4009() throws Exception { + doTest("compiler/testData/diagnostics/tests/smartCasts/inference/kt4009.kt"); + } + } public static Test innerSuite() {