[FIR] Add optin on API of updating type of receiver values. KT-54708
This commit is contained in:
committed by
Space Team
parent
e6ce008415
commit
7af43176ce
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
|||||||
import org.jetbrains.kotlin.fir.resolve.constructType
|
import org.jetbrains.kotlin.fir.resolve.constructType
|
||||||
import org.jetbrains.kotlin.fir.resolve.scope
|
import org.jetbrains.kotlin.fir.resolve.scope
|
||||||
import org.jetbrains.kotlin.fir.resolve.smartcastScope
|
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.FakeOverrideTypeCalculator
|
||||||
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
|
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||||
@@ -100,10 +99,20 @@ sealed class ImplicitReceiverValue<S : FirBasedSymbol<*>>(
|
|||||||
final override var receiverExpression: FirExpression = originalReceiverExpression
|
final override var receiverExpression: FirExpression = originalReceiverExpression
|
||||||
private set
|
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
|
* Should be called only in ImplicitReceiverStack
|
||||||
*/
|
*/
|
||||||
fun replaceType(type: ConeKotlinType) {
|
@ImplicitReceiverInternals
|
||||||
|
fun updateTypeFromSmartcast(type: ConeKotlinType) {
|
||||||
if (type == this.type) return
|
if (type == this.type) return
|
||||||
if (!mutable) throw IllegalStateException("Cannot mutate an immutable ImplicitReceiverValue")
|
if (!mutable) throw IllegalStateException("Cannot mutate an immutable ImplicitReceiverValue")
|
||||||
this.type = type
|
this.type = type
|
||||||
|
|||||||
+2
-1
@@ -242,7 +242,8 @@ class FirBuilderInferenceSession(
|
|||||||
lambda.transformSingle(stubTypeSubstitutor, null)
|
lambda.transformSingle(stubTypeSubstitutor, null)
|
||||||
|
|
||||||
for (receiver in lambdaImplicitReceivers) {
|
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]
|
// TODO: support diagnostics, see [CoroutineInferenceSession#updateCalls]
|
||||||
|
|||||||
+2
-1
@@ -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
|
// 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
|
// 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) {
|
fun replaceReceiverType(index: Int, type: ConeKotlinType) {
|
||||||
assert(index >= 0 && index < stack.size)
|
assert(index >= 0 && index < stack.size)
|
||||||
stack[index].replaceType(type)
|
stack[index].updateTypeFromSmartcast(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createSnapshot(): PersistentImplicitReceiverStack {
|
fun createSnapshot(): PersistentImplicitReceiverStack {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// IGNORE_LEAKED_INTERNAL_TYPES: KT-54708
|
||||||
// WITH_STDLIB
|
// WITH_STDLIB
|
||||||
|
|
||||||
import kotlin.experimental.ExperimentalTypeInference
|
import kotlin.experimental.ExperimentalTypeInference
|
||||||
|
|||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// IGNORE_LEAKED_INTERNAL_TYPES: KT-54708
|
||||||
// !OPT_IN: kotlin.RequiresOptIn
|
// !OPT_IN: kotlin.RequiresOptIn
|
||||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
// ISSUE: KT-35684
|
// ISSUE: KT-35684
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// IGNORE_LEAKED_INTERNAL_TYPES: KT-54708
|
||||||
// !OPT_IN: kotlin.RequiresOptIn
|
// !OPT_IN: kotlin.RequiresOptIn
|
||||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
// ISSUE: KT-35684
|
// ISSUE: KT-35684
|
||||||
|
|||||||
Reference in New Issue
Block a user