Skip to content

Commit d40f0b9

Browse files
lunakolySpace Team
authored andcommitted
[FIR] Downgrade RedundantExplicitTypeChecker to experimental checkers
The checker produces a false positive on integer literals: ``` val it: Long = 0 ``` Looks like we don't have the information about how the literal looked like initially: we have `kind`, but it's replaced when we fix the literal variable to a specific type with the actual type information, thus duplicating it. The fix probably deserves a separate refactoring. ^KT-69938
1 parent 0f56fc7 commit d40f0b9

File tree

12 files changed

+68
-10
lines changed

12 files changed

+68
-10
lines changed

analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsWithLatestLanguageVersionTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/ExperimentalDeclarationCheckers.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ package org.jetbrains.kotlin.fir.analysis.checkers
88
import org.jetbrains.kotlin.fir.analysis.cfa.FirReturnsImpliesAnalyzer
99
import org.jetbrains.kotlin.fir.analysis.checkers.cfa.FirControlFlowChecker
1010
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.*
11+
import org.jetbrains.kotlin.fir.analysis.checkers.experimental.RedundantExplicitTypeChecker
1112

1213
object ExperimentalDeclarationCheckers : DeclarationCheckers() {
1314
override val controlFlowAnalyserCheckers: Set<FirControlFlowChecker>
1415
get() = setOf(
1516
FirReturnsImpliesAnalyzer,
1617
)
18+
19+
override val propertyCheckers: Set<FirPropertyChecker>
20+
get() = setOf(
21+
RedundantExplicitTypeChecker,
22+
)
1723
}

compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/ExtraDeclarationCheckers.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ object ExtraDeclarationCheckers : DeclarationCheckers() {
2929
override val propertyCheckers: Set<FirPropertyChecker>
3030
get() = setOf(
3131
RedundantSetterParameterTypeChecker,
32-
RedundantExplicitTypeChecker,
3332
)
33+
3434
override val variableAssignmentCfaBasedCheckers: Set<AbstractFirPropertyInitializationChecker>
3535
get() = setOf(
3636
CanBeValChecker,
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
/*
2-
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

6-
package org.jetbrains.kotlin.fir.analysis.checkers.extra
6+
package org.jetbrains.kotlin.fir.analysis.checkers.experimental
77

88
import org.jetbrains.kotlin.KtFakeSourceElementKind
99
import org.jetbrains.kotlin.KtNodeTypes
10-
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
11-
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirPropertyChecker
1210
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
13-
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
1411
import org.jetbrains.kotlin.diagnostics.reportOn
1512
import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind
13+
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
14+
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirPropertyChecker
15+
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
1616
import org.jetbrains.kotlin.fir.declarations.FirProperty
1717
import org.jetbrains.kotlin.fir.expressions.*
1818
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
19-
import org.jetbrains.kotlin.fir.resolve.toSymbol
20-
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
2119
import org.jetbrains.kotlin.fir.types.*
2220
import org.jetbrains.kotlin.name.ClassId
2321
import org.jetbrains.kotlin.name.Name
@@ -94,4 +92,4 @@ object RedundantExplicitTypeChecker : FirPropertyChecker(MppCheckerKind.Common)
9492

9593
private fun ConeKotlinType.hasSameNameWithoutModifiers(name: Name): Boolean =
9694
this is ConeClassLikeType && lookupTag.name == name && typeArguments.isEmpty() && !isMarkedNullable
97-
}
95+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
$TESTDATA_DIR$/extendedCheckers.kt
2-
-Xuse-fir-extra-checkers
2+
-Xuse-fir-experimental-checkers
33
-d
44
$TEMP_DIR$
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// WITH_EXPERIMENTAL_CHECKERS
2+
3+
inline fun <T> Iterable<T>.sumByLong(selector: (T) -> Long): Long {
4+
var sum: <!REDUNDANT_EXPLICIT_TYPE!>Long<!> = 0
5+
for (element in this) {
6+
sum += selector(element)
7+
}
8+
return sum
9+
}

0 commit comments

Comments
 (0)