KT-3174 Call resolver doesn't understand type is not-nullable after ?. safe call
#KT-3174 fixed
This commit is contained in:
@@ -276,8 +276,11 @@ public class CandidateResolver {
|
||||
ReceiverValue receiverArgument = candidateCall.getReceiverArgument();
|
||||
ReceiverParameterDescriptor receiverParameter = candidateWithFreshVariables.getReceiverParameter();
|
||||
if (receiverArgument.exists() && receiverParameter != null) {
|
||||
constraintsSystem.addSubtypeConstraint(receiverParameter.getType(), receiverArgument.getType(),
|
||||
ConstraintPosition.RECEIVER_POSITION);
|
||||
JetType receiverType =
|
||||
context.candidateCall.isSafeCall()
|
||||
? TypeUtils.makeNotNullable(receiverArgument.getType())
|
||||
: receiverArgument.getType();
|
||||
constraintsSystem.addSubtypeConstraint(receiverParameter.getType(), receiverType, ConstraintPosition.RECEIVER_POSITION);
|
||||
}
|
||||
|
||||
ConstraintSystem
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
//KT-3174 Call resolver doesn't understand type is not-nullable after ?. safe call
|
||||
package a
|
||||
|
||||
fun <T: Any> T.test(): T = this
|
||||
fun foo(a: Any?) = a?.test() // Error
|
||||
|
||||
fun <T> T.fff(l: MutableList<T>) = l.add(this)
|
||||
|
||||
fun test(s: String?, l: MutableList<String>) {
|
||||
s?.fff(l)
|
||||
|
||||
}
|
||||
@@ -2247,6 +2247,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
doTest("compiler/testData/diagnostics/tests/inference/regressions/kt3150.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt3174.kt")
|
||||
public void testKt3174() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/inference/regressions/kt3174.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt702.kt")
|
||||
public void testKt702() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/inference/regressions/kt702.kt");
|
||||
|
||||
Reference in New Issue
Block a user