FIR: create constructors copies with correct containers in JvmMappedScope
#KT-49133 Fixed
This commit is contained in:
committed by
TeamCityServer
parent
a2b9c2bd78
commit
7b9ac4c5f7
@@ -1674,7 +1674,7 @@ KtConstructorSymbol:
|
|||||||
annotationClassIds: []
|
annotationClassIds: []
|
||||||
annotations: []
|
annotations: []
|
||||||
callableIdIfNonLocal: null
|
callableIdIfNonLocal: null
|
||||||
containingClassIdIfNonLocal: java/lang/Integer
|
containingClassIdIfNonLocal: kotlin/Int
|
||||||
dispatchType: null
|
dispatchType: null
|
||||||
hasStableParameterNames: false
|
hasStableParameterNames: false
|
||||||
isExtension: false
|
isExtension: false
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.scopes.jvm
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltInsSignatures
|
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltInsSignatures
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
|
import org.jetbrains.kotlin.fir.containingClassForStaticMemberAttr
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.classId
|
import org.jetbrains.kotlin.fir.declarations.utils.classId
|
||||||
@@ -27,17 +28,19 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
class JvmMappedScope(
|
class JvmMappedScope(
|
||||||
private val session: FirSession,
|
private val session: FirSession,
|
||||||
private val firKotlinClass: FirClass,
|
private val firKotlinClass: FirClass,
|
||||||
private val firJavaClass: FirRegularClass,
|
firJavaClass: FirRegularClass,
|
||||||
private val declaredMemberScope: FirContainingNamesAwareScope,
|
private val declaredMemberScope: FirContainingNamesAwareScope,
|
||||||
private val javaMappedClassUseSiteScope: FirTypeScope,
|
private val javaMappedClassUseSiteScope: FirTypeScope,
|
||||||
private val signatures: Signatures
|
private val signatures: Signatures
|
||||||
) : FirTypeScope() {
|
) : FirTypeScope() {
|
||||||
private val functionsCache = mutableMapOf<FirNamedFunctionSymbol, FirNamedFunctionSymbol>()
|
private val functionsCache = mutableMapOf<FirNamedFunctionSymbol, FirNamedFunctionSymbol>()
|
||||||
|
|
||||||
|
private val constructorsCache = mutableMapOf<FirConstructorSymbol, FirConstructorSymbol>()
|
||||||
|
|
||||||
private val substitutor = ConeSubstitutorByMap(
|
private val substitutor = ConeSubstitutorByMap(
|
||||||
firJavaClass.typeParameters.zip(firKotlinClass.typeParameters).map { (javaParameter, kotlinParameter) ->
|
firJavaClass.typeParameters.zip(firKotlinClass.typeParameters).associate { (javaParameter, kotlinParameter) ->
|
||||||
javaParameter.symbol to ConeTypeParameterTypeImpl(ConeTypeParameterLookupTag(kotlinParameter.symbol), isNullable = false)
|
javaParameter.symbol to ConeTypeParameterTypeImpl(ConeTypeParameterLookupTag(kotlinParameter.symbol), isNullable = false)
|
||||||
}.toMap(),
|
},
|
||||||
session
|
session
|
||||||
)
|
)
|
||||||
private val kotlinDispatchReceiverType = firKotlinClass.defaultType()
|
private val kotlinDispatchReceiverType = firKotlinClass.defaultType()
|
||||||
@@ -98,16 +101,43 @@ class JvmMappedScope(
|
|||||||
javaMappedClassUseSiteScope.processDeclaredConstructors { symbol ->
|
javaMappedClassUseSiteScope.processDeclaredConstructors { symbol ->
|
||||||
val jvmSignature = symbol.fir.computeJvmDescriptor()
|
val jvmSignature = symbol.fir.computeJvmDescriptor()
|
||||||
if (jvmSignature !in hiddenConstructors) {
|
if (jvmSignature !in hiddenConstructors) {
|
||||||
processor(symbol)
|
val newSymbol = getOrCreateCopy(symbol)
|
||||||
|
processor(newSymbol)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
javaMappedClassUseSiteScope.processDeclaredConstructors(processor)
|
javaMappedClassUseSiteScope.processDeclaredConstructors { symbol ->
|
||||||
|
val newSymbol = getOrCreateCopy(symbol)
|
||||||
|
processor(newSymbol)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declaredMemberScope.processDeclaredConstructors(processor)
|
declaredMemberScope.processDeclaredConstructors(processor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getOrCreateCopy(symbol: FirConstructorSymbol): FirConstructorSymbol {
|
||||||
|
return constructorsCache.getOrPut(symbol) {
|
||||||
|
val oldConstructor = symbol.fir
|
||||||
|
val classId = firKotlinClass.classId
|
||||||
|
val newSymbol = FirConstructorSymbol(CallableId(classId, classId.shortClassName))
|
||||||
|
FirFakeOverrideGenerator.createCopyForFirConstructor(
|
||||||
|
newSymbol,
|
||||||
|
session,
|
||||||
|
oldConstructor,
|
||||||
|
symbol.fir.origin,
|
||||||
|
newDispatchReceiverType = null,
|
||||||
|
newReturnType = substitutor.substituteOrSelf(oldConstructor.returnTypeRef.coneType),
|
||||||
|
newParameterTypes = oldConstructor.valueParameters.map { substitutor.substituteOrSelf(it.returnTypeRef.coneType) },
|
||||||
|
newTypeParameters = null,
|
||||||
|
isExpect = false,
|
||||||
|
fakeOverrideSubstitution = null
|
||||||
|
).apply {
|
||||||
|
containingClassForStaticMemberAttr = firKotlinClass.symbol.toLookupTag()
|
||||||
|
}
|
||||||
|
newSymbol
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun processDirectOverriddenPropertiesWithBaseScope(
|
override fun processDirectOverriddenPropertiesWithBaseScope(
|
||||||
propertySymbol: FirPropertySymbol,
|
propertySymbol: FirPropertySymbol,
|
||||||
processor: (FirPropertySymbol, FirTypeScope) -> ProcessorAction
|
processor: (FirPropertySymbol, FirTypeScope) -> ProcessorAction
|
||||||
|
|||||||
+2
-1
@@ -189,10 +189,11 @@ class FirClassSubstitutionScope(
|
|||||||
return original
|
return original
|
||||||
}
|
}
|
||||||
|
|
||||||
return FirFakeOverrideGenerator.createSubstitutionOverrideConstructor(
|
return FirFakeOverrideGenerator.createCopyForFirConstructor(
|
||||||
FirConstructorSymbol(original.callableId),
|
FirConstructorSymbol(original.callableId),
|
||||||
session,
|
session,
|
||||||
constructor,
|
constructor,
|
||||||
|
FirDeclarationOrigin.SubstitutionOverride,
|
||||||
newDispatchReceiverType,
|
newDispatchReceiverType,
|
||||||
newReturnType,
|
newReturnType,
|
||||||
newParameterTypes,
|
newParameterTypes,
|
||||||
|
|||||||
+3
-2
@@ -118,10 +118,11 @@ object FirFakeOverrideGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createSubstitutionOverrideConstructor(
|
fun createCopyForFirConstructor(
|
||||||
fakeOverrideSymbol: FirConstructorSymbol,
|
fakeOverrideSymbol: FirConstructorSymbol,
|
||||||
session: FirSession,
|
session: FirSession,
|
||||||
baseConstructor: FirConstructor,
|
baseConstructor: FirConstructor,
|
||||||
|
origin: FirDeclarationOrigin,
|
||||||
newDispatchReceiverType: ConeKotlinType?,
|
newDispatchReceiverType: ConeKotlinType?,
|
||||||
newReturnType: ConeKotlinType?,
|
newReturnType: ConeKotlinType?,
|
||||||
newParameterTypes: List<ConeKotlinType?>?,
|
newParameterTypes: List<ConeKotlinType?>?,
|
||||||
@@ -133,7 +134,7 @@ object FirFakeOverrideGenerator {
|
|||||||
// As second alternative, we can invent some light-weight kind of FirRegularClass
|
// As second alternative, we can invent some light-weight kind of FirRegularClass
|
||||||
return buildConstructor {
|
return buildConstructor {
|
||||||
moduleData = session.moduleData
|
moduleData = session.moduleData
|
||||||
origin = FirDeclarationOrigin.SubstitutionOverride
|
this.origin = origin
|
||||||
receiverTypeRef = baseConstructor.receiverTypeRef?.withReplacedConeType(null)
|
receiverTypeRef = baseConstructor.receiverTypeRef?.withReplacedConeType(null)
|
||||||
status = baseConstructor.status.copy(isExpect)
|
status = baseConstructor.status.copy(isExpect)
|
||||||
symbol = fakeOverrideSymbol
|
symbol = fakeOverrideSymbol
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ interface A2 : List<String> {
|
|||||||
override fun stream(): java.util.stream.Stream<String> = null!!
|
override fun stream(): java.util.stream.Stream<String> = null!!
|
||||||
}
|
}
|
||||||
|
|
||||||
class B : <!NONE_APPLICABLE!>Throwable<!>("", null, false, false)
|
class B : Throwable("", null, false, false)
|
||||||
|
|
||||||
class B1 : RuntimeException() {
|
class B1 : RuntimeException() {
|
||||||
override fun fillInStackTrace(): Throwable { // 'override' keyword must be prohibited, as it was in 1.0.x
|
override fun fillInStackTrace(): Throwable { // 'override' keyword must be prohibited, as it was in 1.0.x
|
||||||
|
|||||||
Reference in New Issue
Block a user