[FIR] Split origin SubstitutionOverride into declaration and call-site

This commit is contained in:
Kirill Rakhman
2023-06-07 16:12:14 +02:00
committed by Space Team
parent 67fc46a190
commit bcdd85758e
12 changed files with 70 additions and 40 deletions
@@ -24,7 +24,7 @@ internal class JavaClassDeclaredMembersEnhancementScope(
) : FirContainingNamesAwareScope() { ) : FirContainingNamesAwareScope() {
private fun FirCallableDeclaration.isDeclared(): Boolean { private fun FirCallableDeclaration.isDeclared(): Boolean {
return (this.dispatchReceiverType as? ConeLookupTagBasedType)?.lookupTag == owner.symbol.toLookupTag() return (this.dispatchReceiverType as? ConeLookupTagBasedType)?.lookupTag == owner.symbol.toLookupTag()
&& this.origin != FirDeclarationOrigin.SubstitutionOverride && this.origin !is FirDeclarationOrigin.SubstitutionOverride
&& this.origin != FirDeclarationOrigin.IntersectionOverride && this.origin != FirDeclarationOrigin.IntersectionOverride
} }
@@ -100,7 +100,7 @@ internal tailrec fun FirDeclaration.ktSymbolOrigin(): KtSymbolOrigin = when (ori
is FirDeclarationOrigin.Plugin -> KtSymbolOrigin.PLUGIN is FirDeclarationOrigin.Plugin -> KtSymbolOrigin.PLUGIN
FirDeclarationOrigin.RenamedForOverride -> KtSymbolOrigin.JAVA FirDeclarationOrigin.RenamedForOverride -> KtSymbolOrigin.JAVA
FirDeclarationOrigin.SubstitutionOverride -> KtSymbolOrigin.SUBSTITUTION_OVERRIDE is FirDeclarationOrigin.SubstitutionOverride -> KtSymbolOrigin.SUBSTITUTION_OVERRIDE
FirDeclarationOrigin.DynamicScope -> buildErrorWithAttachment("Invalid FirDeclarationOrigin ${origin::class.simpleName}") { FirDeclarationOrigin.DynamicScope -> buildErrorWithAttachment("Invalid FirDeclarationOrigin ${origin::class.simpleName}") {
withFirEntry("firToGetOrigin", this@ktSymbolOrigin) withFirEntry("firToGetOrigin", this@ktSymbolOrigin)
} }
@@ -70,7 +70,7 @@ private fun collectDesignationPath(target: FirElementWithResolveState): List<Fir
val containingClassId = target.containingClassLookupTag()?.classId ?: return emptyList() val containingClassId = target.containingClassLookupTag()?.classId ?: return emptyList()
if (target.origin == FirDeclarationOrigin.SubstitutionOverride) { if (target.origin is FirDeclarationOrigin.SubstitutionOverride) {
val originalContainingClassId = target.originalForSubstitutionOverride?.containingClassLookupTag()?.classId val originalContainingClassId = target.originalForSubstitutionOverride?.containingClassLookupTag()?.classId
if (containingClassId == originalContainingClassId) { if (containingClassId == originalContainingClassId) {
// Ugly temporary hack for call-site substitution overrides (KTIJ-24004). // Ugly temporary hack for call-site substitution overrides (KTIJ-24004).
@@ -2,7 +2,7 @@ C:
[Source]: public open override fun getName(): R|kotlin/String| from Use site scope of /C [id: 0] [Source]: public open override fun getName(): R|kotlin/String| from Use site scope of /C [id: 0]
[Enhancement]: public abstract fun getName(): R|kotlin/String!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1] [Enhancement]: public abstract fun getName(): R|kotlin/String!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1]
[Source]: public open override fun setName(newName: R|kotlin/String|): R|kotlin/Any?| from Use site scope of /C [id: 0] [Source]: public open override fun setName(newName: R|kotlin/String|): R|kotlin/Any?| from Use site scope of /C [id: 0]
[SubstitutionOverride]: public abstract fun setName(newName: R|kotlin/String!|): R|kotlin/Any!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1] [SubstitutionOverride(DeclarationSite)]: public abstract fun setName(newName: R|kotlin/String!|): R|kotlin/Any!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1]
[Enhancement]: public abstract fun setName(newName: R|kotlin/String!|): R|ft<T & Any, T?>| from Java enhancement scope for /B [id: 2] [Enhancement]: public abstract fun setName(newName: R|kotlin/String!|): R|ft<T & Any, T?>| from Java enhancement scope for /B [id: 2]
[Source]: private final var name: R|kotlin/String| = R|<local>/name| from Use site scope of /C [id: 0] [Source]: private final var name: R|kotlin/String| = R|<local>/name| from Use site scope of /C [id: 0]
@@ -10,7 +10,7 @@ D:
[Source]: public open override fun getName(): R|kotlin/String| from Java enhancement scope for /D [id: 0] [Source]: public open override fun getName(): R|kotlin/String| from Java enhancement scope for /D [id: 0]
[Enhancement]: public abstract fun getName(): R|kotlin/String!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1] [Enhancement]: public abstract fun getName(): R|kotlin/String!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1]
[Source]: public open override fun setName(newName: R|kotlin/String|): R|kotlin/Any?| from Java enhancement scope for /D [id: 0] [Source]: public open override fun setName(newName: R|kotlin/String|): R|kotlin/Any?| from Java enhancement scope for /D [id: 0]
[SubstitutionOverride]: public abstract fun setName(newName: R|kotlin/String!|): R|kotlin/Any!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1] [SubstitutionOverride(DeclarationSite)]: public abstract fun setName(newName: R|kotlin/String!|): R|kotlin/Any!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1]
[Enhancement]: public abstract fun setName(newName: R|kotlin/String!|): R|ft<T & Any, T?>| from Java enhancement scope for /B [id: 2] [Enhancement]: public abstract fun setName(newName: R|kotlin/String!|): R|ft<T & Any, T?>| from Java enhancement scope for /B [id: 2]
[Source]: private final var name: R|kotlin/String| = R|<local>/name| from Java enhancement scope for /D [id: 0] [Source]: private final var name: R|kotlin/String| = R|<local>/name| from Java enhancement scope for /D [id: 0]
[Source]: private final var name: R|kotlin/String| = R|<local>/name| from Use site scope of /C [id: 0] [Source]: private final var name: R|kotlin/String| = R|<local>/name| from Use site scope of /C [id: 0]
@@ -1,38 +1,38 @@
SomeMap: SomeMap:
[Enhancement]: public abstract fun containsKey(key: R|ft<K3 & Any, K3?>|): R|kotlin/Boolean| from Java enhancement scope for /SomeMap [id: 0] [Enhancement]: public abstract fun containsKey(key: R|ft<K3 & Any, K3?>|): R|kotlin/Boolean| from Java enhancement scope for /SomeMap [id: 0]
[SubstitutionOverride]: public abstract fun containsKey(key: R|ft<K3 & Any, K3?>|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableMap] for type SomeMap<K3, V3> [id: 1] [SubstitutionOverride(DeclarationSite)]: public abstract fun containsKey(key: R|ft<K3 & Any, K3?>|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableMap] for type SomeMap<K3, V3> [id: 1]
[SubstitutionOverride]: public abstract fun containsKey(key: R|K|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableMap [id: 2] [SubstitutionOverride(DeclarationSite)]: public abstract fun containsKey(key: R|K|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableMap [id: 2]
[Library]: public abstract fun containsKey(key: R|K|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 3] [Library]: public abstract fun containsKey(key: R|K|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 3]
[Library]: public abstract fun containsKey(key: R|K|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 3] [Library]: public abstract fun containsKey(key: R|K|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 3]
[SubstitutionOverride]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyMap] for type SomeMap<K3, V3> [id: 4] [SubstitutionOverride(DeclarationSite)]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyMap] for type SomeMap<K3, V3> [id: 4]
[Enhancement]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyMap [id: 5] [Enhancement]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyMap [id: 5]
[SubstitutionOverride]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyBaseMap] for type MyMap<K2, V2> [id: 6] [SubstitutionOverride(DeclarationSite)]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyBaseMap] for type MyMap<K2, V2> [id: 6]
[Enhancement]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyBaseMap [id: 7] [Enhancement]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyBaseMap [id: 7]
[SubstitutionOverride]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyBaseMap] for type MyMap<K2, V2> [id: 6] [SubstitutionOverride(DeclarationSite)]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyBaseMap] for type MyMap<K2, V2> [id: 6]
[Enhancement]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyBaseMap [id: 7] [Enhancement]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyBaseMap [id: 7]
[IntersectionOverride]: public abstract fun containsValue(value: R|ft<V3 & Any, V3?>|): R|kotlin/Boolean| from Java enhancement scope for /SomeMap [id: 0] [IntersectionOverride]: public abstract fun containsValue(value: R|ft<V3 & Any, V3?>|): R|kotlin/Boolean| from Java enhancement scope for /SomeMap [id: 0]
[SubstitutionOverride]: public abstract fun containsValue(value: R|ft<V3 & Any, V3?>|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableMap] for type SomeMap<K3, V3> [id: 1] [SubstitutionOverride(DeclarationSite)]: public abstract fun containsValue(value: R|ft<V3 & Any, V3?>|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableMap] for type SomeMap<K3, V3> [id: 1]
[SubstitutionOverride]: public abstract fun containsValue(value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableMap [id: 2] [SubstitutionOverride(DeclarationSite)]: public abstract fun containsValue(value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableMap [id: 2]
[Library]: public abstract fun containsValue(value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 3] [Library]: public abstract fun containsValue(value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 3]
[Library]: public abstract fun containsValue(value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 3] [Library]: public abstract fun containsValue(value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 3]
[SubstitutionOverride]: public abstract fun containsValue(key: R|kotlin/Any!|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyMap] for type SomeMap<K3, V3> [id: 4] [SubstitutionOverride(DeclarationSite)]: public abstract fun containsValue(key: R|kotlin/Any!|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyMap] for type SomeMap<K3, V3> [id: 4]
[Enhancement]: public abstract fun containsValue(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyMap [id: 5] [Enhancement]: public abstract fun containsValue(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyMap [id: 5]
[IntersectionOverride]: public abstract operator fun get(key: R|ft<K3 & Any, K3?>|): R|V3?| from Java enhancement scope for /SomeMap [id: 0] [IntersectionOverride]: public abstract operator fun get(key: R|ft<K3 & Any, K3?>|): R|V3?| from Java enhancement scope for /SomeMap [id: 0]
[SubstitutionOverride]: public abstract operator fun get(key: R|ft<K3 & Any, K3?>|): R|V3?| from Substitution scope for [Use site scope of kotlin/collections/MutableMap] for type SomeMap<K3, V3> [id: 1] [SubstitutionOverride(DeclarationSite)]: public abstract operator fun get(key: R|ft<K3 & Any, K3?>|): R|V3?| from Substitution scope for [Use site scope of kotlin/collections/MutableMap] for type SomeMap<K3, V3> [id: 1]
[SubstitutionOverride]: public abstract operator fun get(key: R|K|): R|V?| from Use site scope of kotlin/collections/MutableMap [id: 2] [SubstitutionOverride(DeclarationSite)]: public abstract operator fun get(key: R|K|): R|V?| from Use site scope of kotlin/collections/MutableMap [id: 2]
[Library]: public abstract operator fun get(key: R|K|): R|V?| from Use site scope of kotlin/collections/Map [id: 3] [Library]: public abstract operator fun get(key: R|K|): R|V?| from Use site scope of kotlin/collections/Map [id: 3]
[Library]: public abstract operator fun get(key: R|K|): R|V?| from Use site scope of kotlin/collections/Map [id: 3] [Library]: public abstract operator fun get(key: R|K|): R|V?| from Use site scope of kotlin/collections/Map [id: 3]
[SubstitutionOverride]: public abstract operator fun get(key: R|ft<K3 & Any, K3?>|): R|ft<V3 & Any, V3?>| from Substitution scope for [Java enhancement scope for /MyMap] for type SomeMap<K3, V3> [id: 4] [SubstitutionOverride(DeclarationSite)]: public abstract operator fun get(key: R|ft<K3 & Any, K3?>|): R|ft<V3 & Any, V3?>| from Substitution scope for [Java enhancement scope for /MyMap] for type SomeMap<K3, V3> [id: 4]
[Enhancement]: public abstract operator fun get(key: R|ft<K2 & Any, K2?>|): R|ft<V2 & Any, V2?>| from Java enhancement scope for /MyMap [id: 5] [Enhancement]: public abstract operator fun get(key: R|ft<K2 & Any, K2?>|): R|ft<V2 & Any, V2?>| from Java enhancement scope for /MyMap [id: 5]
[Enhancement]: public abstract fun remove(key: R|ft<K3 & Any, K3?>|): R|V3?| from Java enhancement scope for /SomeMap [id: 0] [Enhancement]: public abstract fun remove(key: R|ft<K3 & Any, K3?>|): R|V3?| from Java enhancement scope for /SomeMap [id: 0]
[SubstitutionOverride]: public abstract fun remove(key: R|ft<K3 & Any, K3?>|): R|V3?| from Substitution scope for [Use site scope of kotlin/collections/MutableMap] for type SomeMap<K3, V3> [id: 1] [SubstitutionOverride(DeclarationSite)]: public abstract fun remove(key: R|ft<K3 & Any, K3?>|): R|V3?| from Substitution scope for [Use site scope of kotlin/collections/MutableMap] for type SomeMap<K3, V3> [id: 1]
[Library]: public abstract fun remove(key: R|K|): R|V?| from Use site scope of kotlin/collections/MutableMap [id: 2] [Library]: public abstract fun remove(key: R|K|): R|V?| from Use site scope of kotlin/collections/MutableMap [id: 2]
[SubstitutionOverride]: public open fun remove(key: R|ft<K3 & Any, K3?>|, value: R|ft<V3 & Any, V3?>|): R|kotlin/Boolean| from Java enhancement scope for /SomeMap [id: 0] [SubstitutionOverride(DeclarationSite)]: public open fun remove(key: R|ft<K3 & Any, K3?>|, value: R|ft<V3 & Any, V3?>|): R|kotlin/Boolean| from Java enhancement scope for /SomeMap [id: 0]
[Library]: public open fun remove(key: R|K|, value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableMap [id: 1] [Library]: public open fun remove(key: R|K|, value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableMap [id: 1]
MyMap: MyMap:
[Enhancement]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyMap [id: 0] [Enhancement]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyMap [id: 0]
[SubstitutionOverride]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyBaseMap] for type MyMap<K2, V2> [id: 1] [SubstitutionOverride(DeclarationSite)]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyBaseMap] for type MyMap<K2, V2> [id: 1]
[Enhancement]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyBaseMap [id: 2] [Enhancement]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyBaseMap [id: 2]
[Enhancement]: public abstract fun containsValue(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyMap [id: 0] [Enhancement]: public abstract fun containsValue(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyMap [id: 0]
[Enhancement]: public abstract operator fun get(key: R|ft<K2 & Any, K2?>|): R|ft<V2 & Any, V2?>| from Java enhancement scope for /MyMap [id: 0] [Enhancement]: public abstract operator fun get(key: R|ft<K2 & Any, K2?>|): R|ft<V2 & Any, V2?>| from Java enhancement scope for /MyMap [id: 0]
@@ -136,6 +136,7 @@ class FakeOverrideGenerator(
session, symbol, firFunction, session, symbol, firFunction,
derivedClassLookupTag = firClass.symbol.toLookupTag(), derivedClassLookupTag = firClass.symbol.toLookupTag(),
newDispatchReceiverType = firClass.defaultType(), newDispatchReceiverType = firClass.defaultType(),
origin = FirDeclarationOrigin.SubstitutionOverride.DeclarationSite,
isExpect = (firClass as? FirRegularClass)?.isExpect == true || firFunction.isExpect isExpect = (firClass as? FirRegularClass)?.isExpect == true || firFunction.isExpect
) )
}, },
@@ -164,6 +165,7 @@ class FakeOverrideGenerator(
session, symbolForOverride, firProperty, session, symbolForOverride, firProperty,
derivedClassLookupTag = firClass.symbol.toLookupTag(), derivedClassLookupTag = firClass.symbol.toLookupTag(),
newDispatchReceiverType = firClass.defaultType(), newDispatchReceiverType = firClass.defaultType(),
origin = FirDeclarationOrigin.SubstitutionOverride.DeclarationSite,
isExpect = (firClass as? FirRegularClass)?.isExpect == true || firProperty.isExpect isExpect = (firClass as? FirRegularClass)?.isExpect == true || firProperty.isExpect
) )
}, },
@@ -192,6 +194,7 @@ class FakeOverrideGenerator(
session, firField, session, firField,
derivedClassLookupTag = firClass.symbol.toLookupTag(), derivedClassLookupTag = firClass.symbol.toLookupTag(),
newReturnType = firField.returnTypeRef.coneType, newReturnType = firField.returnTypeRef.coneType,
origin = FirDeclarationOrigin.SubstitutionOverride.DeclarationSite,
) )
}, },
baseStaticFieldSymbols, baseStaticFieldSymbols,
@@ -344,6 +347,7 @@ class FakeOverrideGenerator(
session, callableSymbol, firFunction, session, callableSymbol, firFunction,
derivedClassLookupTag = klass.symbol.toLookupTag(), derivedClassLookupTag = klass.symbol.toLookupTag(),
newDispatchReceiverType = klass.defaultType(), newDispatchReceiverType = klass.defaultType(),
origin = FirDeclarationOrigin.SubstitutionOverride.DeclarationSite,
isExpect = (klass as? FirRegularClass)?.isExpect == true || firFunction.isExpect isExpect = (klass as? FirRegularClass)?.isExpect == true || firFunction.isExpect
) )
}, },
@@ -363,6 +367,7 @@ class FakeOverrideGenerator(
session, callableSymbol, firProperty, session, callableSymbol, firProperty,
derivedClassLookupTag = klass.symbol.toLookupTag(), derivedClassLookupTag = klass.symbol.toLookupTag(),
newDispatchReceiverType = klass.defaultType(), newDispatchReceiverType = klass.defaultType(),
origin = FirDeclarationOrigin.SubstitutionOverride.DeclarationSite,
isExpect = (klass as? FirRegularClass)?.isExpect == true || firProperty.isExpect isExpect = (klass as? FirRegularClass)?.isExpect == true || firProperty.isExpect
) )
}, },
@@ -376,7 +381,7 @@ class FakeOverrideGenerator(
scope: FirScope, scope: FirScope,
containingClass: ConeClassLikeLookupTag, containingClass: ConeClassLikeLookupTag,
): List<S> { ): List<S> {
if (symbol.fir.origin == FirDeclarationOrigin.SubstitutionOverride) { if (symbol.fir.origin is FirDeclarationOrigin.SubstitutionOverride) {
return listOf(symbol.originalForSubstitutionOverride!!) return listOf(symbol.originalForSubstitutionOverride!!)
} }
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.FirSessionComponent import org.jetbrains.kotlin.fir.FirSessionComponent
import org.jetbrains.kotlin.fir.declarations.FirClass import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.declarations.utils.delegateFields import org.jetbrains.kotlin.fir.declarations.utils.delegateFields
@@ -207,7 +208,12 @@ private fun FirClass.scopeForClassImpl(
substitutor.substituteOrSelf(classFirDispatchReceiver.defaultType()).lowerBoundIfFlexible() as ConeClassLikeType, substitutor.substituteOrSelf(classFirDispatchReceiver.defaultType()).lowerBoundIfFlexible() as ConeClassLikeType,
skipPrivateMembers, skipPrivateMembers,
makeExpect = isFromExpectClass, makeExpect = isFromExpectClass,
memberOwnerLookupTag ?: classFirDispatchReceiver.symbol.toLookupTag() memberOwnerLookupTag ?: classFirDispatchReceiver.symbol.toLookupTag(),
origin = if (classFirDispatchReceiver != this) {
FirDeclarationOrigin.SubstitutionOverride.DeclarationSite
} else {
FirDeclarationOrigin.SubstitutionOverride.CallSite
},
) )
} }
} }
@@ -35,7 +35,8 @@ class FirClassSubstitutionScope(
private val dispatchReceiverTypeForSubstitutedMembers: ConeClassLikeType, private val dispatchReceiverTypeForSubstitutedMembers: ConeClassLikeType,
private val skipPrivateMembers: Boolean, private val skipPrivateMembers: Boolean,
private val makeExpect: Boolean = false, private val makeExpect: Boolean = false,
private val derivedClassLookupTag: ConeClassLikeLookupTag private val derivedClassLookupTag: ConeClassLikeLookupTag,
private val origin: FirDeclarationOrigin.SubstitutionOverride,
) : FirTypeScope() { ) : FirTypeScope() {
private val substitutionOverrideCache = session.substitutionOverrideStorage.substitutionOverrideCacheByScope.getValue(key, null) private val substitutionOverrideCache = session.substitutionOverrideStorage.substitutionOverrideCacheByScope.getValue(key, null)
@@ -147,6 +148,7 @@ class FirClassSubstitutionScope(
derivedClassLookupTag = derivedClassLookupTag, derivedClassLookupTag = derivedClassLookupTag,
newDispatchReceiverType ?: dispatchReceiverTypeForSubstitutedMembers, newDispatchReceiverType ?: dispatchReceiverTypeForSubstitutedMembers,
isExpect = makeExpect, isExpect = makeExpect,
origin = origin,
) )
} }
return original return original
@@ -163,6 +165,7 @@ class FirClassSubstitutionScope(
member, member,
derivedClassLookupTag, derivedClassLookupTag,
newDispatchReceiverType ?: dispatchReceiverTypeForSubstitutedMembers, newDispatchReceiverType ?: dispatchReceiverTypeForSubstitutedMembers,
origin,
newReceiverType, newReceiverType,
newContextReceiverTypes, newContextReceiverTypes,
newReturnType, newReturnType,
@@ -208,7 +211,7 @@ class FirClassSubstitutionScope(
session, session,
constructor, constructor,
derivedClassLookupTag, derivedClassLookupTag,
FirDeclarationOrigin.SubstitutionOverride, origin,
newDispatchReceiverType, newDispatchReceiverType,
// Constructors' return types are expected to be non-flexible (i.e., non raw) // Constructors' return types are expected to be non-flexible (i.e., non raw)
newReturnType?.lowerBoundIfFlexible(), newReturnType?.lowerBoundIfFlexible(),
@@ -249,6 +252,7 @@ class FirClassSubstitutionScope(
member, member,
derivedClassLookupTag = derivedClassLookupTag, derivedClassLookupTag = derivedClassLookupTag,
newDispatchReceiverType ?: dispatchReceiverTypeForSubstitutedMembers, newDispatchReceiverType ?: dispatchReceiverTypeForSubstitutedMembers,
origin,
isExpect = makeExpect, isExpect = makeExpect,
) )
} }
@@ -262,6 +266,7 @@ class FirClassSubstitutionScope(
member, member,
derivedClassLookupTag, derivedClassLookupTag,
newDispatchReceiverType ?: dispatchReceiverTypeForSubstitutedMembers, newDispatchReceiverType ?: dispatchReceiverTypeForSubstitutedMembers,
origin,
newReceiverType, newReceiverType,
newContextReceiverTypes, newContextReceiverTypes,
newReturnType, newReturnType,
@@ -289,6 +294,7 @@ class FirClassSubstitutionScope(
member as FirTypeParameterRefsOwner, member as FirTypeParameterRefsOwner,
symbolForOverride, symbolForOverride,
substitutor, substitutor,
origin,
forceTypeParametersRecreation = dispatchReceiverTypeForSubstitutedMembers.lookupTag != memberOwnerClassLookupTag forceTypeParametersRecreation = dispatchReceiverTypeForSubstitutedMembers.lookupTag != memberOwnerClassLookupTag
) )
@@ -320,7 +326,7 @@ class FirClassSubstitutionScope(
// TODO: do we have fields with implicit type? // TODO: do we have fields with implicit type?
val newReturnType = returnType?.substitute() ?: return original val newReturnType = returnType?.substitute() ?: return original
return FirFakeOverrideGenerator.createSubstitutionOverrideField(session, member, derivedClassLookupTag, newReturnType) return FirFakeOverrideGenerator.createSubstitutionOverrideField(session, member, derivedClassLookupTag, newReturnType, origin)
} }
override fun processDeclaredConstructors(processor: (FirConstructorSymbol) -> Unit) { override fun processDeclaredConstructors(processor: (FirConstructorSymbol) -> Unit) {
@@ -37,6 +37,7 @@ object FirFakeOverrideGenerator {
baseFunction: FirSimpleFunction, baseFunction: FirSimpleFunction,
derivedClassLookupTag: ConeClassLikeLookupTag?, derivedClassLookupTag: ConeClassLikeLookupTag?,
newDispatchReceiverType: ConeSimpleKotlinType?, newDispatchReceiverType: ConeSimpleKotlinType?,
origin: FirDeclarationOrigin.SubstitutionOverride,
newReceiverType: ConeKotlinType? = null, newReceiverType: ConeKotlinType? = null,
newContextReceiverTypes: List<ConeKotlinType?>? = null, newContextReceiverTypes: List<ConeKotlinType?>? = null,
newReturnType: ConeKotlinType? = null, newReturnType: ConeKotlinType? = null,
@@ -47,7 +48,7 @@ object FirFakeOverrideGenerator {
): FirNamedFunctionSymbol { ): FirNamedFunctionSymbol {
createSubstitutionOverrideFunction( createSubstitutionOverrideFunction(
symbolForSubstitutionOverride, session, baseFunction, derivedClassLookupTag, newDispatchReceiverType, newReceiverType, symbolForSubstitutionOverride, session, baseFunction, derivedClassLookupTag, newDispatchReceiverType, newReceiverType,
newContextReceiverTypes, newReturnType, newParameterTypes, newTypeParameters, isExpect, fakeOverrideSubstitution newContextReceiverTypes, newReturnType, newParameterTypes, newTypeParameters, isExpect, fakeOverrideSubstitution, origin,
) )
return symbolForSubstitutionOverride return symbolForSubstitutionOverride
} }
@@ -73,6 +74,7 @@ object FirFakeOverrideGenerator {
newTypeParameters: List<FirTypeParameter>?, newTypeParameters: List<FirTypeParameter>?,
isExpect: Boolean = baseFunction.isExpect, isExpect: Boolean = baseFunction.isExpect,
fakeOverrideSubstitution: FakeOverrideSubstitution?, fakeOverrideSubstitution: FakeOverrideSubstitution?,
origin: FirDeclarationOrigin.SubstitutionOverride,
): FirSimpleFunction { ): FirSimpleFunction {
// TODO: consider using here some light-weight functions instead of pseudo-real FirMemberFunctionImpl // TODO: consider using here some light-weight functions instead of pseudo-real FirMemberFunctionImpl
// As second alternative, we can invent some light-weight kind of FirRegularClass // As second alternative, we can invent some light-weight kind of FirRegularClass
@@ -81,7 +83,7 @@ object FirFakeOverrideGenerator {
baseFunction, baseFunction,
derivedClassLookupTag = derivedClassLookupTag, derivedClassLookupTag = derivedClassLookupTag,
session, session,
FirDeclarationOrigin.SubstitutionOverride, origin,
isExpect, isExpect,
newDispatchReceiverType, newDispatchReceiverType,
newParameterTypes, newParameterTypes,
@@ -210,13 +212,14 @@ object FirFakeOverrideGenerator {
newReceiverType, newReceiverType,
newContextReceiverTypes, newContextReceiverTypes,
newReturnType, newReturnType,
fakeOverrideSubstitution fakeOverrideSubstitution,
origin,
) )
emptyList() emptyList()
} }
newTypeParameters == null -> { newTypeParameters == null -> {
val (copiedTypeParameters, substitutor) = createNewTypeParametersAndSubstitutor( val (copiedTypeParameters, substitutor) = createNewTypeParametersAndSubstitutor(
useSiteSession, baseFunction, symbolForOverride, ConeSubstitutor.Empty useSiteSession, baseFunction, symbolForOverride, ConeSubstitutor.Empty, origin
) )
val copiedParameterTypes = baseFunction.valueParameters.map { val copiedParameterTypes = baseFunction.valueParameters.map {
substitutor.substituteOrNull(it.returnTypeRef.coneType) substitutor.substituteOrNull(it.returnTypeRef.coneType)
@@ -236,7 +239,8 @@ object FirFakeOverrideGenerator {
copiedReceiverType, copiedReceiverType,
copiedContextReceiverTypes, copiedContextReceiverTypes,
copiedReturnType, copiedReturnType,
newFakeOverrideSubstitution newFakeOverrideSubstitution,
origin,
) )
copiedTypeParameters copiedTypeParameters
} }
@@ -248,7 +252,8 @@ object FirFakeOverrideGenerator {
newReceiverType, newReceiverType,
newContextReceiverTypes, newContextReceiverTypes,
newReturnType, newReturnType,
fakeOverrideSubstitution fakeOverrideSubstitution,
origin,
) )
newTypeParameters newTypeParameters
} }
@@ -263,6 +268,7 @@ object FirFakeOverrideGenerator {
newContextReceiverTypes: List<ConeKotlinType?>?, newContextReceiverTypes: List<ConeKotlinType?>?,
newReturnType: ConeKotlinType?, newReturnType: ConeKotlinType?,
fakeOverrideSubstitution: FakeOverrideSubstitution?, fakeOverrideSubstitution: FakeOverrideSubstitution?,
origin: FirDeclarationOrigin,
) { ) {
annotations += baseFunction.annotations annotations += baseFunction.annotations
@@ -289,7 +295,7 @@ object FirFakeOverrideGenerator {
newParameterTypes ?: List(baseFunction.valueParameters.size) { null } newParameterTypes ?: List(baseFunction.valueParameters.size) { null }
) { valueParameter, newType -> ) { valueParameter, newType ->
buildValueParameterCopy(valueParameter) { buildValueParameterCopy(valueParameter) {
origin = FirDeclarationOrigin.SubstitutionOverride this.origin = origin
returnTypeRef = valueParameter.returnTypeRef.withReplacedConeType(newType) returnTypeRef = valueParameter.returnTypeRef.withReplacedConeType(newType)
symbol = FirValueParameterSymbol(valueParameter.name) symbol = FirValueParameterSymbol(valueParameter.name)
containingFunctionSymbol = fakeFunctionSymbol containingFunctionSymbol = fakeFunctionSymbol
@@ -313,6 +319,7 @@ object FirFakeOverrideGenerator {
baseProperty: FirProperty, baseProperty: FirProperty,
derivedClassLookupTag: ConeClassLikeLookupTag, derivedClassLookupTag: ConeClassLikeLookupTag,
newDispatchReceiverType: ConeSimpleKotlinType?, newDispatchReceiverType: ConeSimpleKotlinType?,
origin: FirDeclarationOrigin.SubstitutionOverride,
newReceiverType: ConeKotlinType? = null, newReceiverType: ConeKotlinType? = null,
newContextReceiverTypes: List<ConeKotlinType?>? = null, newContextReceiverTypes: List<ConeKotlinType?>? = null,
newReturnType: ConeKotlinType? = null, newReturnType: ConeKotlinType? = null,
@@ -321,7 +328,7 @@ object FirFakeOverrideGenerator {
fakeOverrideSubstitution: FakeOverrideSubstitution? = null fakeOverrideSubstitution: FakeOverrideSubstitution? = null
): FirPropertySymbol { ): FirPropertySymbol {
createCopyForFirProperty( createCopyForFirProperty(
symbolForSubstitutionOverride, baseProperty, derivedClassLookupTag, session, FirDeclarationOrigin.SubstitutionOverride, symbolForSubstitutionOverride, baseProperty, derivedClassLookupTag, session, origin,
isExpect, newDispatchReceiverType, newTypeParameters, newReceiverType, newContextReceiverTypes, newReturnType, isExpect, newDispatchReceiverType, newTypeParameters, newReceiverType, newContextReceiverTypes, newReturnType,
fakeOverrideSubstitution = fakeOverrideSubstitution fakeOverrideSubstitution = fakeOverrideSubstitution
).apply { ).apply {
@@ -481,7 +488,7 @@ object FirFakeOverrideGenerator {
}.also { accessor -> }.also { accessor ->
when (accessor.origin) { when (accessor.origin) {
FirDeclarationOrigin.IntersectionOverride -> accessor.originalForIntersectionOverrideAttr = this FirDeclarationOrigin.IntersectionOverride -> accessor.originalForIntersectionOverrideAttr = this
FirDeclarationOrigin.SubstitutionOverride -> accessor.originalForSubstitutionOverrideAttr = this is FirDeclarationOrigin.SubstitutionOverride -> accessor.originalForSubstitutionOverrideAttr = this
else -> {} else -> {}
} }
@@ -544,7 +551,7 @@ object FirFakeOverrideGenerator {
} }
newTypeParameters == null -> { newTypeParameters == null -> {
val (copiedTypeParameters, substitutor) = createNewTypeParametersAndSubstitutor( val (copiedTypeParameters, substitutor) = createNewTypeParametersAndSubstitutor(
useSiteSession, baseProperty, symbol, ConeSubstitutor.Empty useSiteSession, baseProperty, symbol, ConeSubstitutor.Empty, origin,
) )
val (copiedReceiverType, copiedContextReceiverTypes, possibleReturnType) = substituteReceiverAndReturnType( val (copiedReceiverType, copiedContextReceiverTypes, possibleReturnType) = substituteReceiverAndReturnType(
baseProperty, newReceiverType, newContextReceiverTypes, newReturnType, substitutor baseProperty, newReceiverType, newContextReceiverTypes, newReturnType, substitutor
@@ -642,13 +649,14 @@ object FirFakeOverrideGenerator {
session: FirSession, session: FirSession,
baseField: FirField, baseField: FirField,
derivedClassLookupTag: ConeClassLikeLookupTag, derivedClassLookupTag: ConeClassLikeLookupTag,
newReturnType: ConeKotlinType? newReturnType: ConeKotlinType?,
origin: FirDeclarationOrigin.SubstitutionOverride,
): FirFieldSymbol { ): FirFieldSymbol {
val symbol = FirFieldSymbol(CallableId(derivedClassLookupTag.classId, baseField.name)) val symbol = FirFieldSymbol(CallableId(derivedClassLookupTag.classId, baseField.name))
buildField { buildField {
moduleData = session.nullableModuleData ?: baseField.moduleData moduleData = session.nullableModuleData ?: baseField.moduleData
this.symbol = symbol this.symbol = symbol
origin = FirDeclarationOrigin.SubstitutionOverride this.origin = origin
returnTypeRef = baseField.returnTypeRef.withReplacedConeType(newReturnType) returnTypeRef = baseField.returnTypeRef.withReplacedConeType(newReturnType)
source = baseField.source source = baseField.source
@@ -673,6 +681,7 @@ object FirFakeOverrideGenerator {
member: FirTypeParameterRefsOwner, member: FirTypeParameterRefsOwner,
symbolForOverride: FirBasedSymbol<*>, symbolForOverride: FirBasedSymbol<*>,
substitutor: ConeSubstitutor, substitutor: ConeSubstitutor,
origin: FirDeclarationOrigin,
forceTypeParametersRecreation: Boolean = true forceTypeParametersRecreation: Boolean = true
): Pair<List<FirTypeParameterRef>, ConeSubstitutor> { ): Pair<List<FirTypeParameterRef>, ConeSubstitutor> {
if (member.typeParameters.isEmpty()) return Pair(member.typeParameters, substitutor) if (member.typeParameters.isEmpty()) return Pair(member.typeParameters, substitutor)
@@ -681,7 +690,7 @@ object FirFakeOverrideGenerator {
FirTypeParameterBuilder().apply { FirTypeParameterBuilder().apply {
source = typeParameter.source source = typeParameter.source
moduleData = typeParameter.moduleData moduleData = typeParameter.moduleData
origin = FirDeclarationOrigin.SubstitutionOverride this.origin = origin
resolvePhase = FirResolvePhase.DECLARATIONS resolvePhase = FirResolvePhase.DECLARATIONS
name = typeParameter.name name = typeParameter.name
symbol = FirTypeParameterSymbol() symbol = FirTypeParameterSymbol()
@@ -563,7 +563,7 @@ fun FirFunction.getAsForbiddenNamedArgumentsTarget(
FirDeclarationOrigin.ImportedFromObjectOrStatic -> FirDeclarationOrigin.ImportedFromObjectOrStatic ->
importedFromObjectOrStaticData?.original?.getAsForbiddenNamedArgumentsTarget(session) importedFromObjectOrStaticData?.original?.getAsForbiddenNamedArgumentsTarget(session)
FirDeclarationOrigin.IntersectionOverride, FirDeclarationOrigin.SubstitutionOverride, FirDeclarationOrigin.Delegated -> { FirDeclarationOrigin.IntersectionOverride, is FirDeclarationOrigin.SubstitutionOverride, FirDeclarationOrigin.Delegated -> {
var result: ForbiddenNamedArgumentsTarget? = var result: ForbiddenNamedArgumentsTarget? =
unwrapFakeOverridesOrDelegated().getAsForbiddenNamedArgumentsTarget(session) ?: return null unwrapFakeOverridesOrDelegated().getAsForbiddenNamedArgumentsTarget(session) ?: return null
originScope?.processOverriddenFunctions(symbol as FirNamedFunctionSymbol) { originScope?.processOverriddenFunctions(symbol as FirNamedFunctionSymbol) {
@@ -27,7 +27,11 @@ sealed class FirDeclarationOrigin(
object SamConstructor : FirDeclarationOrigin() object SamConstructor : FirDeclarationOrigin()
object Enhancement : FirDeclarationOrigin() object Enhancement : FirDeclarationOrigin()
object ImportedFromObjectOrStatic : FirDeclarationOrigin() object ImportedFromObjectOrStatic : FirDeclarationOrigin()
object SubstitutionOverride : FirDeclarationOrigin(fromSupertypes = true) sealed class SubstitutionOverride(displayName: String) : FirDeclarationOrigin(displayName, fromSupertypes = true) {
object DeclarationSite : SubstitutionOverride("SubstitutionOverride(DeclarationSite)")
object CallSite : SubstitutionOverride("SubstitutionOverride(CallSite)")
}
object IntersectionOverride : FirDeclarationOrigin(fromSupertypes = true) object IntersectionOverride : FirDeclarationOrigin(fromSupertypes = true)
object Delegated : FirDeclarationOrigin() object Delegated : FirDeclarationOrigin()
object RenamedForOverride : FirDeclarationOrigin() object RenamedForOverride : FirDeclarationOrigin()
@@ -91,7 +91,7 @@ val FirProperty.hasBackingField: Boolean
if (symbol is FirSyntheticPropertySymbol) return false if (symbol is FirSyntheticPropertySymbol) return false
if (isStatic) return false // For Enum.entries if (isStatic) return false // For Enum.entries
when (origin) { when (origin) {
FirDeclarationOrigin.SubstitutionOverride -> return false is FirDeclarationOrigin.SubstitutionOverride -> return false
FirDeclarationOrigin.IntersectionOverride -> return false FirDeclarationOrigin.IntersectionOverride -> return false
FirDeclarationOrigin.Delegated -> return false FirDeclarationOrigin.Delegated -> return false
else -> { else -> {