[FIR] Implement isHiddenEverywhereBesideSuperCalls logic for constructors
#KT-61448 Fixed
This commit is contained in:
committed by
Space Team
parent
2f49272c42
commit
24367e0ad8
@@ -286,15 +286,19 @@ class JvmMappedScope(
|
||||
newReturnType = substitutor.substituteOrSelf(oldFunction.returnTypeRef.coneType),
|
||||
newSource = oldFunction.source,
|
||||
).apply {
|
||||
if (jdkMemberStatus == JDKMemberStatus.HIDDEN) {
|
||||
isHiddenEverywhereBesideSuperCalls = HiddenEverywhereBesideSuperCallsStatus.HIDDEN
|
||||
} else if (jdkMemberStatus == JDKMemberStatus.HIDDEN_IN_DECLARING_CLASS_ONLY) {
|
||||
isHiddenEverywhereBesideSuperCalls = HiddenEverywhereBesideSuperCallsStatus.HIDDEN_IN_DECLARING_CLASS_ONLY
|
||||
}
|
||||
setHiddenAttributeIfNecessary(jdkMemberStatus)
|
||||
}
|
||||
return newSymbol
|
||||
}
|
||||
|
||||
private fun FirCallableDeclaration.setHiddenAttributeIfNecessary(jdkMemberStatus: JDKMemberStatus) {
|
||||
if (jdkMemberStatus == JDKMemberStatus.HIDDEN) {
|
||||
isHiddenEverywhereBesideSuperCalls = HiddenEverywhereBesideSuperCallsStatus.HIDDEN
|
||||
} else if (jdkMemberStatus == JDKMemberStatus.HIDDEN_IN_DECLARING_CLASS_ONLY) {
|
||||
isHiddenEverywhereBesideSuperCalls = HiddenEverywhereBesideSuperCallsStatus.HIDDEN_IN_DECLARING_CLASS_ONLY
|
||||
}
|
||||
}
|
||||
|
||||
override fun processDirectOverriddenFunctionsWithBaseScope(
|
||||
functionSymbol: FirNamedFunctionSymbol,
|
||||
processor: (FirNamedFunctionSymbol, FirTypeScope) -> ProcessorAction
|
||||
@@ -334,7 +338,13 @@ class JvmMappedScope(
|
||||
if (javaCtor.isTrivialCopyConstructor()) return@processor
|
||||
if (firKotlinClassConstructors.any { javaCtor.isShadowedBy(it) }) return@processor
|
||||
|
||||
val newSymbol = mappedSymbolCache.mappedConstructors.getValue(javaCtorSymbol, this)
|
||||
val jvmDescriptor = javaCtorSymbol.fir.computeJvmDescriptor()
|
||||
val jdkMemberStatus = getJdkMethodStatus(jvmDescriptor)
|
||||
|
||||
if (jdkMemberStatus == JDKMemberStatus.DROP) return@processor
|
||||
|
||||
val newSymbol = mappedSymbolCache.mappedConstructors.getValue(javaCtorSymbol, this to jdkMemberStatus)
|
||||
|
||||
processor(newSymbol)
|
||||
}
|
||||
|
||||
@@ -343,7 +353,7 @@ class JvmMappedScope(
|
||||
|
||||
private fun FirDeclaration.isDeprecated(): Boolean = symbol.getDeprecation(session, callSite = null) != null
|
||||
|
||||
private fun createMappedConstructor(symbol: FirConstructorSymbol): FirConstructorSymbol {
|
||||
private fun createMappedConstructor(symbol: FirConstructorSymbol, jdkMemberStatus: JDKMemberStatus): FirConstructorSymbol {
|
||||
val oldConstructor = symbol.fir
|
||||
val classId = firKotlinClass.classId
|
||||
val newSymbol = FirConstructorSymbol(CallableId(classId, classId.shortClassName))
|
||||
@@ -361,7 +371,9 @@ class JvmMappedScope(
|
||||
isExpect = false,
|
||||
deferredReturnTypeCalculation = null,
|
||||
newSource = oldConstructor.source,
|
||||
)
|
||||
).apply {
|
||||
setHiddenAttributeIfNecessary(jdkMemberStatus)
|
||||
}
|
||||
return newSymbol
|
||||
}
|
||||
|
||||
@@ -398,9 +410,9 @@ class JvmMappedScope(
|
||||
scope.createHiddenFakeFunction(name)
|
||||
}
|
||||
|
||||
val mappedConstructors: FirCache<FirConstructorSymbol, FirConstructorSymbol, JvmMappedScope> =
|
||||
cachesFactory.createCache { symbol, scope ->
|
||||
scope.createMappedConstructor(symbol)
|
||||
val mappedConstructors: FirCache<FirConstructorSymbol, FirConstructorSymbol, Pair<JvmMappedScope, JDKMemberStatus>> =
|
||||
cachesFactory.createCache { symbol, (scope, jdkMemberStatus) ->
|
||||
scope.createMappedConstructor(symbol, jdkMemberStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -774,9 +774,9 @@ internal object CheckHiddenDeclaration : ResolutionStage() {
|
||||
sink.reportDiagnostic(CallToDeprecatedOverrideOfHidden)
|
||||
}
|
||||
|
||||
if (symbol.fir.dispatchReceiverType == null || symbol !is FirNamedFunctionSymbol) return false
|
||||
val isSuperCall = callInfo.callSite.isSuperCall(session)
|
||||
if (symbol.isHidden(isSuperCall, isOverridden = false) == CallToPotentiallyHiddenSymbolResult.Hidden) return true
|
||||
if (symbol.fir.dispatchReceiverType == null || symbol !is FirNamedFunctionSymbol) return false
|
||||
|
||||
val scope = candidate.originScope as? FirTypeScope ?: return false
|
||||
|
||||
|
||||
+6
-2
@@ -1,6 +1,10 @@
|
||||
// !JDK_KIND: MODIFIED_MOCK_JDK
|
||||
abstract class A : Throwable(1.0) {}
|
||||
// K2 difference is in accordance with KT-65438 where we defined that members in the "grey list"
|
||||
// (i.e. neither explicitly visible nor hidden) are hidden in the declaring class and since constructors are not inheritable,
|
||||
// they're always hidden.
|
||||
|
||||
abstract class A : <!NONE_APPLICABLE!>Throwable<!>(1.0) {}
|
||||
|
||||
fun foo() {
|
||||
Throwable(1.5)
|
||||
<!NONE_APPLICABLE!>Throwable<!>(1.5)
|
||||
}
|
||||
|
||||
+4
@@ -1,4 +1,8 @@
|
||||
// !JDK_KIND: MODIFIED_MOCK_JDK
|
||||
// K2 difference is in accordance with KT-65438 where we defined that members in the "grey list"
|
||||
// (i.e. neither explicitly visible nor hidden) are hidden in the declaring class and since constructors are not inheritable,
|
||||
// they're always hidden.
|
||||
|
||||
abstract class A : <!DEPRECATION!>Throwable<!>(1.0) {}
|
||||
|
||||
fun foo() {
|
||||
|
||||
Reference in New Issue
Block a user