KT-4009 Unnecessary attempt to do a smart cast causes an error
#KT-4009 Fixed do not add smart casted types for vars to constraint system
This commit is contained in:
@@ -665,6 +665,8 @@ public class CandidateResolver {
|
||||
|
||||
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(
|
||||
JetPsiUtil.unwrapFromBlock(argumentExpression), type, trace.getBindingContext());
|
||||
if (!dataFlowValue.isStableIdentifier()) return type;
|
||||
|
||||
Set<JetType> possibleTypes = dataFlowInfoForArgument.getPossibleTypes(dataFlowValue);
|
||||
if (possibleTypes.isEmpty()) return type;
|
||||
|
||||
|
||||
@@ -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")
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user