[NI] remove redundant replacing receiver in lambda function descriptor

#KT-30927 Fixed
#KT-31057 Fixed
This commit is contained in:
Dmitriy Novozhilov
2019-04-16 16:02:10 +03:00
parent 2fe900d915
commit 642f8ecaf8
7 changed files with 93 additions and 3 deletions
@@ -19539,6 +19539,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
runTest("compiler/testData/diagnostics/tests/smartCasts/kt30826.kt");
}
@TestMetadata("kt30927.kt")
public void testKt30927() throws Exception {
runTest("compiler/testData/diagnostics/tests/smartCasts/kt30927.kt");
}
@TestMetadata("kt3224.kt")
public void testKt3224() throws Exception {
runTest("compiler/testData/diagnostics/tests/smartCasts/kt3224.kt");
@@ -208,9 +208,11 @@ class ResolvedAtomCompleter(
val newReceiverValue = receiver.value.replaceType(newValueType)
functionDescriptor.setExtensionReceiverParameter(
ReceiverParameterDescriptorImpl(receiver.containingDeclaration, newReceiverValue, receiver.annotations)
)
if (newReceiverValue != receiver.value) {
functionDescriptor.setExtensionReceiverParameter(
ReceiverParameterDescriptorImpl(receiver.containingDeclaration, newReceiverValue, receiver.annotations)
)
}
}
}
@@ -0,0 +1,51 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION
// !WITH_NEW_INFERENCE
// !CHECK_TYPE
fun case_0() {
val z: Any? = 10
val y = z.run {
this as Int
<!NI;DEBUG_INFO_SMARTCAST!>this<!> // error in NI: required Int, found Any?; just inferred to Any? in OI
}
y checkType { <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Any?>() }
y checkType { <!OI;TYPE_MISMATCH!>_<!><Int>() }
}
fun case_1(z: Any?) {
val y = z.run {
when (this) {
is String -> return@run <!NI;DEBUG_INFO_SMARTCAST!>this<!> // type mismatch in the new inference (required String, found Any?)
is Float -> ""
else -> return@run ""
}
}
y checkType { <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Any?>() }
y checkType { <!OI;TYPE_MISMATCH!>_<!><kotlin.String>() }
// y is inferred to Any?
}
fun case_2(z: Any?) {
val y = z.run {
when (this) {
is String -> <!DEBUG_INFO_SMARTCAST!>this<!>
is Float -> ""
else -> return@run ""
}
}
y checkType { _<kotlin.String>() }
// y is inferred to String
}
fun case_3(z: Any?) {
val y = z.let {
when (it) {
is String -> return@let <!NI;DEBUG_INFO_SMARTCAST!>it<!>
is Float -> ""
else -> return@let ""
}
}
y checkType { <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Any?>() }
y checkType { <!OI;TYPE_MISMATCH!>_<!><kotlin.String>() }
// y is inferred to String
}
@@ -0,0 +1,6 @@
package
public fun case_0(): kotlin.Unit
public fun case_1(/*0*/ z: kotlin.Any?): kotlin.Unit
public fun case_2(/*0*/ z: kotlin.Any?): kotlin.Unit
public fun case_3(/*0*/ z: kotlin.Any?): kotlin.Unit
@@ -19616,6 +19616,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
runTest("compiler/testData/diagnostics/tests/smartCasts/kt30826.kt");
}
@TestMetadata("kt30927.kt")
public void testKt30927() throws Exception {
runTest("compiler/testData/diagnostics/tests/smartCasts/kt30927.kt");
}
@TestMetadata("kt3224.kt")
public void testKt3224() throws Exception {
runTest("compiler/testData/diagnostics/tests/smartCasts/kt3224.kt");
@@ -19541,6 +19541,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/smartCasts/kt30826.kt");
}
@TestMetadata("kt30927.kt")
public void testKt30927() throws Exception {
runTest("compiler/testData/diagnostics/tests/smartCasts/kt30927.kt");
}
@TestMetadata("kt3224.kt")
public void testKt3224() throws Exception {
runTest("compiler/testData/diagnostics/tests/smartCasts/kt3224.kt");
@@ -20,7 +20,20 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker;
import java.util.Objects;
/**
* [ExtensionReceiver] is a receiver for pure `this` call inside lambda with receiver
*
* x.run {
* this // ExtensionReceiver
* this as String // ExtensionReceiver
* this.toString() // ImplicitClassReceiver
* toString() // ImplicitClassReceiver
* }
*/
public class ExtensionReceiver extends AbstractReceiverValue implements ImplicitReceiver {
private final CallableDescriptor descriptor;
@@ -43,6 +56,9 @@ public class ExtensionReceiver extends AbstractReceiverValue implements Implicit
@NotNull
@Override
public ReceiverValue replaceType(@NotNull KotlinType newType) {
if (NewKotlinTypeChecker.INSTANCE.equalTypes(receiverType, newType)) {
return this;
}
return new ExtensionReceiver(descriptor, newType, getOriginal());
}