diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirUnderscoreChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirUnderscoreChecker.kt index 73be9769dc3..b80e6198042 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirUnderscoreChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirUnderscoreChecker.kt @@ -14,19 +14,12 @@ import org.jetbrains.kotlin.fir.diagnostics.ConeUnderscoreUsageWithoutBackticks import org.jetbrains.kotlin.fir.expressions.FirResolvable import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier import org.jetbrains.kotlin.fir.expressions.FirStatement -import org.jetbrains.kotlin.fir.expressions.toResolvedCallableSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.fir.analysis.checkers.SourceNavigator object FirUnderscoreChecker : FirBasicExpressionChecker() { - private val singleUnderscore: Name = Name.identifier("_") - override fun check(expression: FirStatement, context: CheckerContext, reporter: DiagnosticReporter) { when (expression) { is FirResolvable -> { checkUnderscoreDiagnostics(expression.calleeReference.source, context, reporter, true) - checkResolvedToUnderscoreNamedCatchParameter(expression, context, reporter) } is FirResolvedQualifier -> { for (reservedUnderscoreDiagnostic in expression.nonFatalDiagnostics) { @@ -37,22 +30,4 @@ object FirUnderscoreChecker : FirBasicExpressionChecker() { } } } - - private fun checkResolvedToUnderscoreNamedCatchParameter( - expression: FirResolvable, - context: CheckerContext, - reporter: DiagnosticReporter - ) { - val calleeReference = expression.calleeReference - val symbol = calleeReference.toResolvedCallableSymbol() - with(SourceNavigator.forElement(expression)) { - if (symbol is FirValueParameterSymbol && symbol.isCatchElementParameter() && symbol.name == singleUnderscore) { - reporter.reportOn( - calleeReference.source, - FirErrors.RESOLVED_TO_UNDERSCORE_NAMED_CATCH_PARAMETER, - context - ) - } - } - } } \ No newline at end of file diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt index f13d124929c..28ec9ddc898 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt @@ -1266,8 +1266,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte return if (valueParameterDeclaration == ValueParameterDeclaration.LAMBDA && rawName == "_" || valueParameterDeclaration == ValueParameterDeclaration.CATCH && - safeName.asString() == "_" && - baseSession.safeLanguageVersionSettings?.supportsFeature(LanguageFeature.ForbidReferencingToUnderscoreNamedParameterOfCatchBlock) == true + safeName.asString() == "_" ) { SpecialNames.UNDERSCORE_FOR_UNUSED_VAR } else { diff --git a/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.fir.kt b/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.fir.kt index c8feb1ac302..cbe03adcd1d 100644 --- a/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.fir.kt @@ -6,7 +6,7 @@ fun foo() { try { TODO() } catch (_: Exception) { - `_`.stackTrace + `_`.stackTrace } try { TODO() @@ -15,22 +15,22 @@ fun foo() { val x2 = { val x3 = { y: Int -> val x4 = { _: Int -> - `_` + `_` } - `_` + `_` } - `_` + `_` 10 } - fun bar(x: Exception = `_`) {} + fun bar(x: Exception = `_`) {} class Bar(`_`: Exception = `_`) { - inner class Bar2(x: Exception = `_`) { } + inner class Bar2(x: Exception = `_`) { } } } } catch (_: Exception) { - `_`.stackTrace - val y1 = _ - val y2 = (`_`) + `_`.stackTrace + val y1 = _ + val y2 = (`_`) } try { TODO() @@ -38,7 +38,7 @@ fun foo() { try { TODO() } catch (x: Exception) { - `_`.stackTrace + `_`.stackTrace } } val boo1 = { `_`: Exception ->