Receiver of a safe call is not null inside the call also for extension functions + a pair of tests #KT-9033 Fixed

This commit is contained in:
Mikhail Glukhikh
2015-09-09 17:43:42 +03:00
parent 22229af930
commit 1667f18d7c
8 changed files with 43 additions and 2 deletions
@@ -75,7 +75,6 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
@NotNull TracingStrategy tracing, @NotNull Call call, @NotNull ReceiverValue explicitExtensionReceiverForInvoke,
@NotNull CandidateResolveMode candidateResolveMode
) {
candidateCall.getDataFlowInfoForArguments().setInitialDataFlowInfo(context.dataFlowInfo);
return new CallCandidateResolutionContext<D>(
candidateCall, tracing, trace, context.scope, call, context.expectedType,
context.dataFlowInfo, context.contextDependency, context.checkArguments,
@@ -86,8 +86,8 @@ public class DataFlowInfoForArgumentsImpl implements MutableDataFlowInfoForArgum
@NotNull
@Override
public DataFlowInfo getResultInfo() {
if (resultInfo == null) return initialInfo;
assert initialInfo != null : "Initial data flow info was not set for call: " + call;
if (resultInfo == null) return initialInfo;
return initialInfo.and(resultInfo);
}
}
@@ -0,0 +1,6 @@
fun String.bar(s: String) = s
fun foo(s: String?) {
s?.bar(<!DEBUG_INFO_SMARTCAST!>s<!>)
s?.charAt(<!DEBUG_INFO_SMARTCAST!>s<!>.length())
}
@@ -0,0 +1,4 @@
package
public fun foo(/*0*/ s: kotlin.String?): kotlin.Unit
public fun kotlin.String.bar(/*0*/ s: kotlin.String): kotlin.String
@@ -0,0 +1,7 @@
// Based on KT-9033
fun f(s: String) = s
fun foo(s: String?) {
s?.let { f(<!DEBUG_INFO_SMARTCAST!>s<!>) }
s?.let { f(it) }
}
@@ -0,0 +1,4 @@
package
public fun f(/*0*/ s: kotlin.String): kotlin.String
public fun foo(/*0*/ s: kotlin.String?): kotlin.Unit
@@ -13895,6 +13895,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("extensionCall.kt")
public void testExtensionCall() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/safecalls/extensionCall.kt");
doTest(fileName);
}
@TestMetadata("falseArgument.kt")
public void testFalseArgument() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/safecalls/falseArgument.kt");
@@ -830,6 +830,21 @@ public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnostic
}
}
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/smartcasts")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Smartcasts extends AbstractJetDiagnosticsTestWithStdLib {
public void testAllFilesPresentInSmartcasts() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/smartcasts"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("letUsesOwnReceiver.kt")
public void testLetUsesOwnReceiver() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/smartcasts/letUsesOwnReceiver.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/varargs")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)