K2: drop C/DFA warning which fixes can break compilation in K1 till 1.8
#KT-50965 Fixed
This commit is contained in:
+12
-1
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.analysis.providers.createAnnotationResolver
|
||||
import org.jetbrains.kotlin.analysis.providers.createDeclarationProvider
|
||||
import org.jetbrains.kotlin.analysis.providers.createPackageProvider
|
||||
import org.jetbrains.kotlin.analysis.utils.errors.checkIsInstance
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
@@ -81,7 +82,17 @@ internal object LLFirSessionFactory {
|
||||
configureSession: (LLFirSession.() -> Unit)? = null
|
||||
): LLFirSourcesSession {
|
||||
sessionsCache[module]?.let { return it as LLFirSourcesSession }
|
||||
val languageVersionSettings = module.languageVersionSettings
|
||||
val languageVersionSettings = object : LanguageVersionSettings by module.languageVersionSettings {
|
||||
override fun getFeatureSupport(feature: LanguageFeature): LanguageFeature.State =
|
||||
if (feature == LanguageFeature.EnableDfaWarningsInK2) LanguageFeature.State.ENABLED
|
||||
else module.languageVersionSettings.getFeatureSupport(feature)
|
||||
|
||||
override fun supportsFeature(feature: LanguageFeature): Boolean =
|
||||
getFeatureSupport(feature).let {
|
||||
it == LanguageFeature.State.ENABLED || it == LanguageFeature.State.ENABLED_WITH_WARNING
|
||||
}
|
||||
}
|
||||
|
||||
val scopeProvider = FirKotlinScopeProvider(::wrapScopeWithJvmMapped)
|
||||
|
||||
val components = LLFirModuleResolveComponents(module, globalResolveComponents, scopeProvider)
|
||||
|
||||
+4
-1
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
@@ -163,7 +164,9 @@ internal fun checkPropertyInitializer(
|
||||
}
|
||||
// TODO: like [BindingContext.MUST_BE_LATEINIT], we should consider variable with uninitialized error.
|
||||
if (backingFieldRequired && !inInterface && isInitialized) {
|
||||
reporter.reportOn(propertySource, FirErrors.UNNECESSARY_LATEINIT, context)
|
||||
if (context.languageVersionSettings.supportsFeature(LanguageFeature.EnableDfaWarningsInK2)) {
|
||||
reporter.reportOn(propertySource, FirErrors.UNNECESSARY_LATEINIT, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-2
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.expression
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.CastingType
|
||||
@@ -34,9 +35,13 @@ object FirCastOperatorsChecker : FirTypeOperatorCallChecker() {
|
||||
if (expression.operation == FirOperation.AS || isSafeAs) {
|
||||
val castType = checkCasting(actualType, targetType, isSafeAs, context)
|
||||
if (castType == CastingType.Impossible) {
|
||||
reporter.reportOn(expression.source, FirErrors.CAST_NEVER_SUCCEEDS, context)
|
||||
if (context.languageVersionSettings.supportsFeature(LanguageFeature.EnableDfaWarningsInK2)) {
|
||||
reporter.reportOn(expression.source, FirErrors.CAST_NEVER_SUCCEEDS, context)
|
||||
}
|
||||
} else if (castType == CastingType.Always) {
|
||||
reporter.reportOn(expression.source, FirErrors.USELESS_CAST, context)
|
||||
if (context.languageVersionSettings.supportsFeature(LanguageFeature.EnableDfaWarningsInK2)) {
|
||||
reporter.reportOn(expression.source, FirErrors.USELESS_CAST, context)
|
||||
}
|
||||
} else if (isCastErased(actualType, targetType, context)) {
|
||||
reporter.reportOn(expression.source, FirErrors.UNCHECKED_CAST, actualType, targetType, context)
|
||||
}
|
||||
|
||||
+2
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.expression
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
@@ -36,7 +37,7 @@ object FirNotNullAssertionChecker : FirCheckNotNullCallChecker() {
|
||||
|
||||
val type = argument.typeRef.coneType.fullyExpandedType(context.session)
|
||||
|
||||
if (!type.canBeNull) {
|
||||
if (!type.canBeNull && context.languageVersionSettings.supportsFeature(LanguageFeature.EnableDfaWarningsInK2)) {
|
||||
reporter.reportOn(expression.source, FirErrors.UNNECESSARY_NOT_NULL_ASSERTION, type, context)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -26,7 +26,9 @@ object FirUnnecessarySafeCallChecker : FirSafeCallExpressionChecker() {
|
||||
return
|
||||
}
|
||||
if (!receiverType.canBeNull) {
|
||||
reporter.reportOn(expression.source, FirErrors.UNNECESSARY_SAFE_CALL, receiverType, context)
|
||||
if (context.languageVersionSettings.supportsFeature(LanguageFeature.EnableDfaWarningsInK2)) {
|
||||
reporter.reportOn(expression.source, FirErrors.UNNECESSARY_SAFE_CALL, receiverType, context)
|
||||
}
|
||||
if (!context.session.languageVersionSettings.supportsFeature(LanguageFeature.SafeCallsAreAlwaysNullable)) {
|
||||
reporter.reportOn(expression.source, FirErrors.SAFE_CALL_WILL_CHANGE_NULLABILITY, context)
|
||||
}
|
||||
|
||||
+7
-2
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.expression
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
@@ -25,12 +26,16 @@ object FirUselessElvisChecker : FirElvisExpressionChecker() {
|
||||
val lhsType = expression.lhs.typeRef.coneType
|
||||
if (lhsType is ConeErrorType) return
|
||||
if (!lhsType.canBeNull) {
|
||||
reporter.reportOn(expression.source, FirErrors.USELESS_ELVIS, lhsType, context)
|
||||
if (context.languageVersionSettings.supportsFeature(LanguageFeature.EnableDfaWarningsInK2)) {
|
||||
reporter.reportOn(expression.source, FirErrors.USELESS_ELVIS, lhsType, context)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (expression.rhs.isNullLiteral) {
|
||||
reporter.reportOn(expression.source, FirErrors.USELESS_ELVIS_RIGHT_IS_NULL, context)
|
||||
if (context.languageVersionSettings.supportsFeature(LanguageFeature.EnableDfaWarningsInK2)) {
|
||||
reporter.reportOn(expression.source, FirErrors.USELESS_ELVIS_RIGHT_IS_NULL, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
$TESTDATA_DIR$/firDfa.kt
|
||||
-Xuse-k2
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
fun foo(x: String?) {
|
||||
if (x != null) {
|
||||
x!!.length
|
||||
}
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
warning: ATTENTION!
|
||||
This build uses experimental K2 compiler:
|
||||
-Xuse-k2
|
||||
OK
|
||||
+5
@@ -28,6 +28,11 @@ class RegisteredDirectivesBuilder {
|
||||
stringDirectives.putWithExistsCheck(this, values)
|
||||
}
|
||||
|
||||
operator fun StringDirective.plus(value: String) {
|
||||
val previous = stringDirectives[this] ?: listOf()
|
||||
stringDirectives[this] = previous + value
|
||||
}
|
||||
|
||||
operator fun StringDirective.unaryMinus() {
|
||||
stringDirectives.remove(this)
|
||||
}
|
||||
|
||||
+6
-2
@@ -143,13 +143,17 @@ fun TestConfigurationBuilder.baseFirDiagnosticTestConfiguration(
|
||||
|
||||
forTestsMatching("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/*") {
|
||||
defaultDirectives {
|
||||
LANGUAGE with "+ExplicitBackingFields"
|
||||
LANGUAGE + "+ExplicitBackingFields"
|
||||
}
|
||||
}
|
||||
|
||||
forTestsMatching("compiler/testData/diagnostics/tests/multiplatform/*") {
|
||||
defaultDirectives {
|
||||
LANGUAGE with "+MultiPlatformProjects"
|
||||
LANGUAGE + "+MultiPlatformProjects"
|
||||
}
|
||||
}
|
||||
|
||||
defaultDirectives {
|
||||
LANGUAGE + "+EnableDfaWarningsInK2"
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
|
||||
import org.jetbrains.kotlin.test.builders.configureFirHandlersStep
|
||||
import org.jetbrains.kotlin.test.builders.firFrontendStep
|
||||
import org.jetbrains.kotlin.test.builders.firHandlersStep
|
||||
import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives
|
||||
import org.jetbrains.kotlin.test.frontend.classic.handlers.FirJspecifyDiagnosticComplianceHandler
|
||||
import org.jetbrains.kotlin.test.frontend.fir.FirFailingTestSuppressor
|
||||
import org.jetbrains.kotlin.test.frontend.fir.handlers.*
|
||||
@@ -22,6 +23,10 @@ abstract class AbstractFirForeignAnnotationsTestBase(kind: ForeignAnnotationsTes
|
||||
frontend = FrontendKinds.FIR
|
||||
}
|
||||
|
||||
defaultDirectives {
|
||||
LanguageSettingsDirectives.LANGUAGE with "+EnableDfaWarningsInK2"
|
||||
}
|
||||
|
||||
useMetaInfoProcessors(::PsiLightTreeMetaInfoProcessor)
|
||||
firFrontendStep()
|
||||
firHandlersStep {
|
||||
|
||||
@@ -364,6 +364,11 @@ public class CliTestGenerated extends AbstractCliTest {
|
||||
runTest("compiler/testData/cli/jvm/fileClassClashMultipleFiles.args");
|
||||
}
|
||||
|
||||
@TestMetadata("firDfa.args")
|
||||
public void testFirDfa() throws Exception {
|
||||
runTest("compiler/testData/cli/jvm/firDfa.args");
|
||||
}
|
||||
|
||||
@TestMetadata("firError.args")
|
||||
public void testFirError() throws Exception {
|
||||
runTest("compiler/testData/cli/jvm/firError.args");
|
||||
|
||||
@@ -261,6 +261,7 @@ enum class LanguageFeature(
|
||||
ForbidUsingExtensionPropertyTypeParameterInDelegate(KOTLIN_1_8, kind = BUG_FIX),
|
||||
ModifierNonBuiltinSuspendFunError(KOTLIN_1_8),
|
||||
SynchronizedSuspendError(KOTLIN_1_8),
|
||||
EnableDfaWarningsInK2(KOTLIN_1_8, kind = OTHER), // KT-50965
|
||||
|
||||
// 1.9
|
||||
|
||||
|
||||
Reference in New Issue
Block a user