[FIR] Add optin on API of updating type of receiver values. KT-54708

This commit is contained in:
Dmitriy Novozhilov
2022-10-28 14:23:20 +03:00
committed by Space Team
parent e6ce008415
commit 7af43176ce
6 changed files with 18 additions and 4 deletions
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.resolve.constructType
import org.jetbrains.kotlin.fir.resolve.scope
import org.jetbrains.kotlin.fir.resolve.smartcastScope
import org.jetbrains.kotlin.fir.resolvedTypeFromPrototype
import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
@@ -100,10 +99,20 @@ sealed class ImplicitReceiverValue<S : FirBasedSymbol<*>>(
final override var receiverExpression: FirExpression = originalReceiverExpression
private set
@RequiresOptIn
annotation class ImplicitReceiverInternals
@OptIn(ImplicitReceiverInternals::class)
@Deprecated(level = DeprecationLevel.ERROR, message = "Builder inference should not modify implicit receivers. KT-54708")
fun updateTypeInBuilderInference(type: ConeKotlinType) {
updateTypeFromSmartcast(type)
}
/*
* Should be called only in ImplicitReceiverStack
*/
fun replaceType(type: ConeKotlinType) {
@ImplicitReceiverInternals
fun updateTypeFromSmartcast(type: ConeKotlinType) {
if (type == this.type) return
if (!mutable) throw IllegalStateException("Cannot mutate an immutable ImplicitReceiverValue")
this.type = type
@@ -242,7 +242,8 @@ class FirBuilderInferenceSession(
lambda.transformSingle(stubTypeSubstitutor, null)
for (receiver in lambdaImplicitReceivers) {
receiver.replaceType(substitutor.substituteOrSelf(receiver.type))
@Suppress("DEPRECATION_ERROR")
receiver.updateTypeInBuilderInference(substitutor.substituteOrSelf(receiver.type))
}
// TODO: support diagnostics, see [CoroutineInferenceSession#updateCalls]
@@ -100,9 +100,10 @@ class PersistentImplicitReceiverStack private constructor(
// This method is only used from DFA and it's in some sense breaks persistence contracts of the data structure
// But it's ok since DFA handles everything properly yet, but still may be it should be rewritten somehow
@OptIn(ImplicitReceiverValue.ImplicitReceiverInternals::class)
fun replaceReceiverType(index: Int, type: ConeKotlinType) {
assert(index >= 0 && index < stack.size)
stack[index].replaceType(type)
stack[index].updateTypeFromSmartcast(type)
}
fun createSnapshot(): PersistentImplicitReceiverStack {
@@ -1,3 +1,4 @@
// IGNORE_LEAKED_INTERNAL_TYPES: KT-54708
// WITH_STDLIB
import kotlin.experimental.ExperimentalTypeInference
@@ -1,3 +1,4 @@
// IGNORE_LEAKED_INTERNAL_TYPES: KT-54708
// !OPT_IN: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_PARAMETER
// ISSUE: KT-35684
@@ -1,3 +1,4 @@
// IGNORE_LEAKED_INTERNAL_TYPES: KT-54708
// !OPT_IN: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_PARAMETER
// ISSUE: KT-35684