[FIR] Drop RESOLVED_TO_UNDERSCORE_NAMED_CATCH_PARAMETER, always resolve to UNRESOLVED_REFERENCE
This commit is contained in:
committed by
TeamCityServer
parent
1150d51bf2
commit
2241887b8f
-25
@@ -14,19 +14,12 @@ import org.jetbrains.kotlin.fir.diagnostics.ConeUnderscoreUsageWithoutBackticks
|
|||||||
import org.jetbrains.kotlin.fir.expressions.FirResolvable
|
import org.jetbrains.kotlin.fir.expressions.FirResolvable
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier
|
import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
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() {
|
object FirUnderscoreChecker : FirBasicExpressionChecker() {
|
||||||
private val singleUnderscore: Name = Name.identifier("_")
|
|
||||||
|
|
||||||
override fun check(expression: FirStatement, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(expression: FirStatement, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
when (expression) {
|
when (expression) {
|
||||||
is FirResolvable -> {
|
is FirResolvable -> {
|
||||||
checkUnderscoreDiagnostics(expression.calleeReference.source, context, reporter, true)
|
checkUnderscoreDiagnostics(expression.calleeReference.source, context, reporter, true)
|
||||||
checkResolvedToUnderscoreNamedCatchParameter(expression, context, reporter)
|
|
||||||
}
|
}
|
||||||
is FirResolvedQualifier -> {
|
is FirResolvedQualifier -> {
|
||||||
for (reservedUnderscoreDiagnostic in expression.nonFatalDiagnostics) {
|
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
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+1
-2
@@ -1266,8 +1266,7 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
|||||||
return if (valueParameterDeclaration == ValueParameterDeclaration.LAMBDA && rawName == "_"
|
return if (valueParameterDeclaration == ValueParameterDeclaration.LAMBDA && rawName == "_"
|
||||||
||
|
||
|
||||||
valueParameterDeclaration == ValueParameterDeclaration.CATCH &&
|
valueParameterDeclaration == ValueParameterDeclaration.CATCH &&
|
||||||
safeName.asString() == "_" &&
|
safeName.asString() == "_"
|
||||||
baseSession.safeLanguageVersionSettings?.supportsFeature(LanguageFeature.ForbidReferencingToUnderscoreNamedParameterOfCatchBlock) == true
|
|
||||||
) {
|
) {
|
||||||
SpecialNames.UNDERSCORE_FOR_UNUSED_VAR
|
SpecialNames.UNDERSCORE_FOR_UNUSED_VAR
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+10
-10
@@ -6,7 +6,7 @@ fun foo() {
|
|||||||
try {
|
try {
|
||||||
TODO()
|
TODO()
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
<!RESOLVED_TO_UNDERSCORE_NAMED_CATCH_PARAMETER!>`_`<!>.stackTrace
|
<!UNRESOLVED_REFERENCE!>`_`<!>.stackTrace
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
TODO()
|
TODO()
|
||||||
@@ -15,22 +15,22 @@ fun foo() {
|
|||||||
val x2 = {
|
val x2 = {
|
||||||
val x3 = { y: Int ->
|
val x3 = { y: Int ->
|
||||||
val x4 = { _: Int ->
|
val x4 = { _: Int ->
|
||||||
<!RESOLVED_TO_UNDERSCORE_NAMED_CATCH_PARAMETER!>`_`<!>
|
<!UNRESOLVED_REFERENCE!>`_`<!>
|
||||||
}
|
}
|
||||||
<!RESOLVED_TO_UNDERSCORE_NAMED_CATCH_PARAMETER!>`_`<!>
|
<!UNRESOLVED_REFERENCE!>`_`<!>
|
||||||
}
|
}
|
||||||
<!RESOLVED_TO_UNDERSCORE_NAMED_CATCH_PARAMETER!>`_`<!>
|
<!UNRESOLVED_REFERENCE!>`_`<!>
|
||||||
10
|
10
|
||||||
}
|
}
|
||||||
fun bar(x: Exception = <!RESOLVED_TO_UNDERSCORE_NAMED_CATCH_PARAMETER!>`_`<!>) {}
|
fun bar(x: Exception = <!UNRESOLVED_REFERENCE!>`_`<!>) {}
|
||||||
class Bar(`_`: Exception = <!UNINITIALIZED_PARAMETER!>`_`<!>) {
|
class Bar(`_`: Exception = <!UNINITIALIZED_PARAMETER!>`_`<!>) {
|
||||||
inner class Bar2(x: Exception = <!RESOLVED_TO_UNDERSCORE_NAMED_CATCH_PARAMETER!>`_`<!>) { }
|
inner class Bar2(x: Exception = <!UNRESOLVED_REFERENCE!>`_`<!>) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
<!RESOLVED_TO_UNDERSCORE_NAMED_CATCH_PARAMETER!>`_`<!>.stackTrace
|
<!UNRESOLVED_REFERENCE!>`_`<!>.stackTrace
|
||||||
val y1 = <!RESOLVED_TO_UNDERSCORE_NAMED_CATCH_PARAMETER, UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>_<!>
|
val y1 = <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS, UNRESOLVED_REFERENCE!>_<!>
|
||||||
val y2 = (<!RESOLVED_TO_UNDERSCORE_NAMED_CATCH_PARAMETER!>`_`<!>)
|
val y2 = (<!UNRESOLVED_REFERENCE!>`_`<!>)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
TODO()
|
TODO()
|
||||||
@@ -38,7 +38,7 @@ fun foo() {
|
|||||||
try {
|
try {
|
||||||
TODO()
|
TODO()
|
||||||
} catch (x: Exception) {
|
} catch (x: Exception) {
|
||||||
<!RESOLVED_TO_UNDERSCORE_NAMED_CATCH_PARAMETER!>`_`<!>.stackTrace
|
<!UNRESOLVED_REFERENCE!>`_`<!>.stackTrace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val boo1 = { `_`: Exception ->
|
val boo1 = { `_`: Exception ->
|
||||||
|
|||||||
Reference in New Issue
Block a user