[FIR] K2: Fix introduced diagnostic UNDERSCORE_USAGE_WITHOUT_BACKTICKS
^KT-60105 Fixed Merge-request: KT-MR-12214 Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
5e8741db1a
commit
56b951152f
+15
-4
@@ -10,16 +10,19 @@ import org.jetbrains.kotlin.fir.analysis.checkers.checkUnderscoreDiagnostics
|
|||||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.checkers.isUnderscore
|
||||||
import org.jetbrains.kotlin.fir.diagnostics.ConeUnderscoreUsageWithoutBackticks
|
import org.jetbrains.kotlin.fir.diagnostics.ConeUnderscoreUsageWithoutBackticks
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirResolvable
|
import org.jetbrains.kotlin.fir.expressions.*
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier
|
import org.jetbrains.kotlin.fir.references.toResolvedSymbol
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||||
|
|
||||||
object FirUnderscoreChecker : FirBasicExpressionChecker() {
|
object FirUnderscoreChecker : FirBasicExpressionChecker() {
|
||||||
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)
|
if (diagnosticsCheckNeeded(expression)) {
|
||||||
|
checkUnderscoreDiagnostics(expression.calleeReference.source, context, reporter, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
is FirResolvedQualifier -> {
|
is FirResolvedQualifier -> {
|
||||||
for (reservedUnderscoreDiagnostic in expression.nonFatalDiagnostics) {
|
for (reservedUnderscoreDiagnostic in expression.nonFatalDiagnostics) {
|
||||||
@@ -30,4 +33,12 @@ object FirUnderscoreChecker : FirBasicExpressionChecker() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun diagnosticsCheckNeeded(expression: FirResolvable): Boolean {
|
||||||
|
return when (expression) {
|
||||||
|
is FirImplicitInvokeCall -> expression.calleeReference.name.asString().isUnderscore
|
||||||
|
is FirCall -> expression.calleeReference.toResolvedSymbol<FirFunctionSymbol<*>>()?.callableId?.callableName?.asString()?.isUnderscore == true
|
||||||
|
else -> true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import kotlin.Deprecated as <!UNDERSCORE_IS_RESERVED!>___<!>
|
import kotlin.Deprecated as <!UNDERSCORE_IS_RESERVED!>___<!>
|
||||||
|
|
||||||
@<!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>___<!>("") data class Pair(val x: Int, val y: Int)
|
@___("") data class Pair(val x: Int, val y: Int)
|
||||||
|
|
||||||
class <!UNDERSCORE_IS_RESERVED!>_<!><<!UNDERSCORE_IS_RESERVED!>________<!>>
|
class <!UNDERSCORE_IS_RESERVED!>_<!><<!UNDERSCORE_IS_RESERVED!>________<!>>
|
||||||
val <!UNDERSCORE_IS_RESERVED!>______<!> = <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>_<!><Int>()
|
val <!UNDERSCORE_IS_RESERVED!>______<!> = <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>_<!><Int>()
|
||||||
|
|||||||
+2
-2
@@ -54,8 +54,8 @@ fun test() {
|
|||||||
x10 as <!UNRESOLVED_REFERENCE!>_<!>
|
x10 as <!UNRESOLVED_REFERENCE!>_<!>
|
||||||
x10 <!CAST_NEVER_SUCCEEDS!>as<!> Foo<<!UNRESOLVED_REFERENCE!>_<!>>
|
x10 <!CAST_NEVER_SUCCEEDS!>as<!> Foo<<!UNRESOLVED_REFERENCE!>_<!>>
|
||||||
|
|
||||||
val x12: Foo<@<!UNDERSCORE_USAGE_WITHOUT_BACKTICKS, UNRESOLVED_REFERENCE!>_<!> Int>? = null
|
val x12: Foo<@<!UNRESOLVED_REFERENCE!>_<!> Int>? = null
|
||||||
val x13: Foo<@<!UNDERSCORE_USAGE_WITHOUT_BACKTICKS, UNRESOLVED_REFERENCE!>_<!>() Int>? = null
|
val x13: Foo<@<!UNRESOLVED_REFERENCE!>_<!>() Int>? = null
|
||||||
val x14: Foo<@Anno(<!UNDERSCORE_USAGE_WITHOUT_BACKTICKS, UNRESOLVED_REFERENCE!>_<!>) Int>? = null
|
val x14: Foo<@Anno(<!UNDERSCORE_USAGE_WITHOUT_BACKTICKS, UNRESOLVED_REFERENCE!>_<!>) Int>? = null
|
||||||
|
|
||||||
val x15: <!UNRESOLVED_REFERENCE!>_<!><<!UNRESOLVED_REFERENCE!>_<!>>? = null
|
val x15: <!UNRESOLVED_REFERENCE!>_<!><<!UNRESOLVED_REFERENCE!>_<!>>? = null
|
||||||
|
|||||||
Reference in New Issue
Block a user