[FIR] Accept opt-in annotations on primary ctor params of properties
For backward compatibility with K1. KT-56177
This commit is contained in:
committed by
Space Team
parent
cfc5bb74ef
commit
fbc0796ed2
+6
@@ -38886,6 +38886,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/overrideInAnonymousObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideInPrimaryConstructor.kt")
|
||||
public void testOverrideInPrimaryConstructor() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/overrideInPrimaryConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("subClassOptInModality.kt")
|
||||
public void testSubClassOptInModality() throws Exception {
|
||||
|
||||
+6
@@ -38886,6 +38886,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/overrideInAnonymousObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideInPrimaryConstructor.kt")
|
||||
public void testOverrideInPrimaryConstructor() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/overrideInPrimaryConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("subClassOptInModality.kt")
|
||||
public void testSubClassOptInModality() throws Exception {
|
||||
|
||||
+6
@@ -38982,6 +38982,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/overrideInAnonymousObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideInPrimaryConstructor.kt")
|
||||
public void testOverrideInPrimaryConstructor() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/overrideInPrimaryConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("subClassOptInModality.kt")
|
||||
public void testSubClassOptInModality() throws Exception {
|
||||
|
||||
+17
-2
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.*
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.correspondingValueParameterFromPrimaryConstructor
|
||||
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
||||
import org.jetbrains.kotlin.fir.references.resolved
|
||||
@@ -329,8 +330,22 @@ object FirOptInUsageBaseChecker {
|
||||
annotationClassId: ClassId,
|
||||
fromSupertype: Boolean
|
||||
): Boolean {
|
||||
return getAnnotationByClassId(annotationClassId, session) != null || isAnnotatedWithOptIn(annotationClassId, session) ||
|
||||
fromSupertype && isAnnotatedWithSubclassOptInRequired(session, annotationClassId)
|
||||
return getAnnotationByClassId(annotationClassId, session) != null ||
|
||||
isAnnotatedWithOptIn(annotationClassId, session) ||
|
||||
fromSupertype && isAnnotatedWithSubclassOptInRequired(session, annotationClassId) ||
|
||||
// Technically wrong but required for K1 compatibility
|
||||
primaryConstructorParameterIsExperimentalityAcceptable(session, annotationClassId)
|
||||
}
|
||||
|
||||
@OptIn(SymbolInternals::class)
|
||||
private fun FirAnnotationContainer.primaryConstructorParameterIsExperimentalityAcceptable(
|
||||
session: FirSession,
|
||||
annotationClassId: ClassId
|
||||
): Boolean {
|
||||
if (this !is FirProperty) return false
|
||||
val parameterSymbol = correspondingValueParameterFromPrimaryConstructor ?: return false
|
||||
|
||||
return parameterSymbol.fir.isExperimentalityAcceptable(session, annotationClassId, fromSupertype = false)
|
||||
}
|
||||
|
||||
private fun FirAnnotationContainer.isAnnotatedWithOptIn(annotationClassId: ClassId, session: FirSession): Boolean {
|
||||
|
||||
+5
-2
@@ -120,9 +120,12 @@ fun FirDeclaration.getDanglingTypeConstraintsOrEmpty(): List<DanglingTypeConstra
|
||||
}
|
||||
|
||||
val FirPropertySymbol.correspondingValueParameterFromPrimaryConstructor: FirValueParameterSymbol?
|
||||
get() = fir.correspondingValueParameterFromPrimaryConstructor
|
||||
|
||||
val FirProperty.correspondingValueParameterFromPrimaryConstructor: FirValueParameterSymbol?
|
||||
get() {
|
||||
if (!fromPrimaryConstructor) return null
|
||||
val initializer = resolvedInitializer as? FirPropertyAccessExpression ?: return null
|
||||
if (fromPrimaryConstructor != true) return null
|
||||
val initializer = initializer as? FirPropertyAccessExpression ?: return null
|
||||
val reference = initializer.calleeReference as? FirPropertyFromParameterResolvedNamedReference ?: return null
|
||||
return reference.resolvedSymbol as? FirValueParameterSymbol
|
||||
}
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// SKIP_TXT
|
||||
// FIR_IDENTICAL
|
||||
|
||||
@RequiresOptIn(level = RequiresOptIn.Level.ERROR)
|
||||
annotation class E
|
||||
|
||||
abstract class Foo {
|
||||
@E
|
||||
abstract val bar: String
|
||||
}
|
||||
|
||||
class SubFoo(
|
||||
@OptIn(E::class)
|
||||
override val bar: String,
|
||||
) : Foo()
|
||||
Generated
+6
@@ -38982,6 +38982,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/overrideInAnonymousObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideInPrimaryConstructor.kt")
|
||||
public void testOverrideInPrimaryConstructor() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/overrideInPrimaryConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("subClassOptInModality.kt")
|
||||
public void testSubClassOptInModality() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user