[FIR] Fix mapped constructor hiding logic
Partially reverts 24367e0ad8
Constructors have their own list of hidden/visible.
We now require the constructor to be in VISIBLE_CONSTRUCTOR_SIGNATURES,
everything else is hidden.
This makes it unnecessary to check HIDDEN_CONSTRUCTOR_SIGNATURES
#KT-65821 Fixed
This commit is contained in:
committed by
Space Team
parent
84f0f6e099
commit
81e0abeb8f
+6
@@ -22560,6 +22560,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/syntheticPropertyOverridden2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("throwableConstructor.kt")
|
||||
public void testThrowableConstructor() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/throwableConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("traitDefaultCall.kt")
|
||||
public void testTraitDefaultCall() throws Exception {
|
||||
|
||||
+6
@@ -22560,6 +22560,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/syntheticPropertyOverridden2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("throwableConstructor.kt")
|
||||
public void testThrowableConstructor() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/throwableConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("traitDefaultCall.kt")
|
||||
public void testTraitDefaultCall() throws Exception {
|
||||
|
||||
+6
@@ -22554,6 +22554,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/syntheticPropertyOverridden2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("throwableConstructor.kt")
|
||||
public void testThrowableConstructor() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/throwableConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("traitDefaultCall.kt")
|
||||
public void testTraitDefaultCall() throws Exception {
|
||||
|
||||
+6
@@ -22560,6 +22560,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/syntheticPropertyOverridden2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("throwableConstructor.kt")
|
||||
public void testThrowableConstructor() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/throwableConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("traitDefaultCall.kt")
|
||||
public void testTraitDefaultCall() throws Exception {
|
||||
|
||||
@@ -334,17 +334,11 @@ class JvmMappedScope(
|
||||
|
||||
if (!javaCtor.status.visibility.isPublicAPI || javaCtor.isDeprecated()) return@processor
|
||||
val signature = SignatureBuildingComponents.signature(firJavaClass.classId, javaCtor.computeJvmDescriptor())
|
||||
if (signature in JvmBuiltInsSignatures.HIDDEN_CONSTRUCTOR_SIGNATURES) return@processor
|
||||
if (signature !in JvmBuiltInsSignatures.VISIBLE_CONSTRUCTOR_SIGNATURES) return@processor
|
||||
if (javaCtor.isTrivialCopyConstructor()) return@processor
|
||||
if (firKotlinClassConstructors.any { javaCtor.isShadowedBy(it) }) return@processor
|
||||
|
||||
val jvmDescriptor = javaCtorSymbol.fir.computeJvmDescriptor()
|
||||
val jdkMemberStatus = getJdkMethodStatus(jvmDescriptor)
|
||||
|
||||
if (jdkMemberStatus == JDKMemberStatus.DROP) return@processor
|
||||
|
||||
val newSymbol = mappedSymbolCache.mappedConstructors.getValue(javaCtorSymbol, this to jdkMemberStatus)
|
||||
|
||||
val newSymbol = mappedSymbolCache.mappedConstructors.getValue(javaCtorSymbol, this)
|
||||
processor(newSymbol)
|
||||
}
|
||||
|
||||
@@ -353,7 +347,7 @@ class JvmMappedScope(
|
||||
|
||||
private fun FirDeclaration.isDeprecated(): Boolean = symbol.getDeprecation(session, callSite = null) != null
|
||||
|
||||
private fun createMappedConstructor(symbol: FirConstructorSymbol, jdkMemberStatus: JDKMemberStatus): FirConstructorSymbol {
|
||||
private fun createMappedConstructor(symbol: FirConstructorSymbol): FirConstructorSymbol {
|
||||
val oldConstructor = symbol.fir
|
||||
val classId = firKotlinClass.classId
|
||||
val newSymbol = FirConstructorSymbol(CallableId(classId, classId.shortClassName))
|
||||
@@ -371,9 +365,7 @@ class JvmMappedScope(
|
||||
isExpect = false,
|
||||
deferredReturnTypeCalculation = null,
|
||||
newSource = oldConstructor.source,
|
||||
).apply {
|
||||
setHiddenAttributeIfNecessary(jdkMemberStatus)
|
||||
}
|
||||
)
|
||||
return newSymbol
|
||||
}
|
||||
|
||||
@@ -410,9 +402,9 @@ class JvmMappedScope(
|
||||
scope.createHiddenFakeFunction(name)
|
||||
}
|
||||
|
||||
val mappedConstructors: FirCache<FirConstructorSymbol, FirConstructorSymbol, Pair<JvmMappedScope, JDKMemberStatus>> =
|
||||
cachesFactory.createCache { symbol, (scope, jdkMemberStatus) ->
|
||||
scope.createMappedConstructor(symbol, jdkMemberStatus)
|
||||
val mappedConstructors: FirCache<FirConstructorSymbol, FirConstructorSymbol, JvmMappedScope> =
|
||||
cachesFactory.createCache { symbol, scope ->
|
||||
scope.createMappedConstructor(symbol)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.hiddenStatusOfCall(isSuperCall, isCallToOverride = false) == CallToPotentiallyHiddenSymbolResult.Hidden) return true
|
||||
if (symbol.fir.dispatchReceiverType == null || symbol !is FirNamedFunctionSymbol) return false
|
||||
|
||||
val scope = candidate.originScope as? FirTypeScope ?: return false
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// FIR_IDENTICAL
|
||||
// FULL_JDK
|
||||
|
||||
class A : Throwable {
|
||||
constructor(message: String?, cause: Throwable?) : super(message, cause)
|
||||
constructor(message: String?) : super(message)
|
||||
constructor(cause: Throwable?) : super(cause)
|
||||
constructor() : super()
|
||||
constructor(message: String?, cause: Throwable?, enableSuppression: Boolean, writableStackTrace: Boolean)
|
||||
: super(message, cause, enableSuppression, writableStackTrace)
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
Throwable("")
|
||||
Throwable(Exception())
|
||||
Throwable()
|
||||
Throwable("", Exception())
|
||||
}
|
||||
Generated
+6
@@ -22560,6 +22560,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/syntheticPropertyOverridden2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("throwableConstructor.kt")
|
||||
public void testThrowableConstructor() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/throwableConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("traitDefaultCall.kt")
|
||||
public void testTraitDefaultCall() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user