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:
-1
@@ -75,7 +75,6 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
|
|||||||
@NotNull TracingStrategy tracing, @NotNull Call call, @NotNull ReceiverValue explicitExtensionReceiverForInvoke,
|
@NotNull TracingStrategy tracing, @NotNull Call call, @NotNull ReceiverValue explicitExtensionReceiverForInvoke,
|
||||||
@NotNull CandidateResolveMode candidateResolveMode
|
@NotNull CandidateResolveMode candidateResolveMode
|
||||||
) {
|
) {
|
||||||
candidateCall.getDataFlowInfoForArguments().setInitialDataFlowInfo(context.dataFlowInfo);
|
|
||||||
return new CallCandidateResolutionContext<D>(
|
return new CallCandidateResolutionContext<D>(
|
||||||
candidateCall, tracing, trace, context.scope, call, context.expectedType,
|
candidateCall, tracing, trace, context.scope, call, context.expectedType,
|
||||||
context.dataFlowInfo, context.contextDependency, context.checkArguments,
|
context.dataFlowInfo, context.contextDependency, context.checkArguments,
|
||||||
|
|||||||
+1
-1
@@ -86,8 +86,8 @@ public class DataFlowInfoForArgumentsImpl implements MutableDataFlowInfoForArgum
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public DataFlowInfo getResultInfo() {
|
public DataFlowInfo getResultInfo() {
|
||||||
if (resultInfo == null) return initialInfo;
|
|
||||||
assert initialInfo != null : "Initial data flow info was not set for call: " + call;
|
assert initialInfo != null : "Initial data flow info was not set for call: " + call;
|
||||||
|
if (resultInfo == null) return initialInfo;
|
||||||
return initialInfo.and(resultInfo);
|
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
|
||||||
+7
@@ -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) }
|
||||||
|
}
|
||||||
+4
@@ -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);
|
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")
|
@TestMetadata("falseArgument.kt")
|
||||||
public void testFalseArgument() throws Exception {
|
public void testFalseArgument() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/safecalls/falseArgument.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/safecalls/falseArgument.kt");
|
||||||
|
|||||||
+15
@@ -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")
|
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/varargs")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user