KT-10483 Missing smart cast on variable in variable as function call

#KT-10483 Fixed
This commit is contained in:
Stanislav Erokhin
2015-12-23 17:48:42 +03:00
parent 4de26bed93
commit 3d44471659
4 changed files with 51 additions and 1 deletions
@@ -296,7 +296,9 @@ class NewResolveOldInference(
val basicCallResolutionContext = basicCallContext.replaceBindingTrace(variable.resolvedCall.trace)
.replaceCall(functionCall)
.replaceContextDependency(ContextDependency.DEPENDENT) // todo
val newContext = Context(scopeTower, OperatorNameConventions.INVOKE, basicCallResolutionContext, tracingForInvoke)
val newScopeTower = ScopeTowerImpl(basicCallResolutionContext, scopeTower.dynamicScope, scopeTower.syntheticScopes, scopeTower.location)
val newContext = Context(newScopeTower, OperatorNameConventions.INVOKE, basicCallResolutionContext, tracingForInvoke)
return variableReceiver to newContext
}
@@ -0,0 +1,17 @@
interface A
class B : A {
operator fun invoke() = this
}
class C : A
operator fun C.invoke(): B = B()
fun foo(arg: A): B? {
if (arg is B) return <!DEBUG_INFO_SMARTCAST!>arg<!>()
if (arg is C) return <!DEBUG_INFO_SMARTCAST!>arg<!>()
return null
}
@@ -0,0 +1,25 @@
package
public fun foo(/*0*/ arg: A): B?
public operator fun C.invoke(): B
public interface A {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class B : A {
public constructor B()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final operator fun invoke(): B
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class C : A {
public constructor C()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -15303,6 +15303,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("kt10483.kt")
public void testKt10483() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/kt10483.kt");
doTest(fileName);
}
@TestMetadata("kt1461.kt")
public void testKt1461() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/kt1461.kt");