[FIR] Implement FirGenericArrayClassLiteralSupport platform feature
^KT-59931 Fixed
This commit is contained in:
committed by
Space Team
parent
9ab6353032
commit
03442e1cee
+20
-1
@@ -9,6 +9,8 @@ import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.FirSessionComponent
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.analysis.getChild
|
||||
@@ -118,7 +120,10 @@ object FirClassLiteralChecker : FirGetClassCallChecker() {
|
||||
private fun ConeKotlinType.isAllowedInClassLiteral(context: CheckerContext): Boolean =
|
||||
when (this) {
|
||||
is ConeClassLikeType -> {
|
||||
if (isNonPrimitiveArray && !context.languageVersionSettings.supportsFeature(LanguageFeature.ProhibitGenericArrayClassLiteral)) {
|
||||
val isPlatformThatAllowsNonPrimitiveArrays = context.session.firGenericArrayClassLiteralSupport.isEnabled
|
||||
val isOldVersionThatAllowsNonPrimitiveArrays =
|
||||
!context.languageVersionSettings.supportsFeature(LanguageFeature.ProhibitGenericArrayClassLiteral)
|
||||
if (isNonPrimitiveArray && (isPlatformThatAllowsNonPrimitiveArrays || isOldVersionThatAllowsNonPrimitiveArrays)) {
|
||||
typeArguments.none { typeArgument ->
|
||||
when (typeArgument) {
|
||||
is ConeStarProjection -> true
|
||||
@@ -132,3 +137,17 @@ object FirClassLiteralChecker : FirGetClassCallChecker() {
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
interface FirGenericArrayClassLiteralSupport : FirSessionComponent {
|
||||
val isEnabled: Boolean
|
||||
|
||||
object Enabled : FirGenericArrayClassLiteralSupport {
|
||||
override val isEnabled: Boolean = true
|
||||
}
|
||||
|
||||
object Disabled : FirGenericArrayClassLiteralSupport {
|
||||
override val isEnabled: Boolean = false
|
||||
}
|
||||
}
|
||||
|
||||
val FirSession.firGenericArrayClassLiteralSupport: FirGenericArrayClassLiteralSupport by FirSession.sessionComponentAccessor()
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.analysis.FirOverridesBackwardCompatibilityHelper
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.FirInlineCheckerPlatformSpecificComponent
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.FirPrimaryConstructorSuperTypeCheckerPlatformComponent
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirNameConflictsTracker
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirGenericArrayClassLiteralSupport
|
||||
import org.jetbrains.kotlin.fir.analysis.jvm.FirJvmOverridesBackwardCompatibilityHelper
|
||||
import org.jetbrains.kotlin.fir.analysis.jvm.checkers.FirJvmAnnotationsPlatformSpecificSupportComponent
|
||||
import org.jetbrains.kotlin.fir.analysis.jvm.checkers.FirJvmInlineCheckerComponent
|
||||
@@ -89,6 +90,7 @@ fun FirSession.registerCommonComponents(languageVersionSettings: LanguageVersion
|
||||
register(FirDeclarationOverloadabilityHelper::class, FirDeclarationOverloadabilityHelperImpl(this))
|
||||
register(FirAnnotationsPlatformSpecificSupportComponent::class, FirAnnotationsPlatformSpecificSupportComponent.Default)
|
||||
register(FirPrimaryConstructorSuperTypeCheckerPlatformComponent::class, FirPrimaryConstructorSuperTypeCheckerPlatformComponent.Default)
|
||||
register(FirGenericArrayClassLiteralSupport::class, FirGenericArrayClassLiteralSupport.Disabled)
|
||||
}
|
||||
|
||||
@OptIn(SessionConfiguration::class)
|
||||
@@ -156,6 +158,7 @@ fun FirSession.registerJavaComponents(
|
||||
register(FirSyntheticNamesProvider::class, FirJavaSyntheticNamesProvider)
|
||||
register(FirOverridesBackwardCompatibilityHelper::class, FirJvmOverridesBackwardCompatibilityHelper)
|
||||
register(FirInlineCheckerPlatformSpecificComponent::class, FirJvmInlineCheckerComponent())
|
||||
register(FirGenericArrayClassLiteralSupport::class, FirGenericArrayClassLiteralSupport.Enabled)
|
||||
}
|
||||
|
||||
// -------------------------- Resolve components --------------------------
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +BareArrayClassLiteral
|
||||
|
||||
val a01 = Array::class
|
||||
val a02 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>Array<<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Array<!>>::class<!>
|
||||
val a03 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>Array<Any?>::class<!>
|
||||
val a04 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>Array<Array<Any?>?>::class<!>
|
||||
val a05 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>Array<IntArray?>::class<!>
|
||||
val a06 = kotlin.Array::class
|
||||
val a07 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>kotlin.Array<IntArray?>::class<!>
|
||||
+6
@@ -24,6 +24,12 @@ public class DiagnosticsNativeTestGenerated extends AbstractDiagnosticsNativeTes
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/nativeTests"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrays_after.kt")
|
||||
public void testArrays_after() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/nativeTests/arrays_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("cloneableInNative.kt")
|
||||
public void testCloneableInNative() throws Exception {
|
||||
|
||||
+6
@@ -28,6 +28,12 @@ public class FirLightTreeOldFrontendNativeDiagnosticsTestGenerated extends Abstr
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/nativeTests"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrays_after.kt")
|
||||
public void testArrays_after() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/nativeTests/arrays_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("cloneableInNative.kt")
|
||||
public void testCloneableInNative() throws Exception {
|
||||
|
||||
+6
@@ -28,6 +28,12 @@ public class FirPsiOldFrontendNativeDiagnosticsTestGenerated extends AbstractFir
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/nativeTests"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrays_after.kt")
|
||||
public void testArrays_after() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/nativeTests/arrays_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("cloneableInNative.kt")
|
||||
public void testCloneableInNative() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user