[FIR] Provide suppression from primary value parameter to property
`@Suppress` annotation has `VALUE_PARAMETER` target, so when a property in the primary constructor is annotated with `@Suppress` it sticks to the parameter. But the suppression should work for all diagnostics reported on the parameter **and** the property ^KT-66258 Fixed
This commit is contained in:
committed by
Space Team
parent
5e742884de
commit
a08df1821f
+22
-2
@@ -13,10 +13,13 @@ import org.jetbrains.kotlin.fir.analysis.checkers.declaration.createInlineFuncti
|
||||
import org.jetbrains.kotlin.fir.contracts.FirContractDescription
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.buildReceiverParameter
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.correspondingValueParameterFromPrimaryConstructor
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isInline
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirContractCallBlock
|
||||
import org.jetbrains.kotlin.fir.resolve.defaultType
|
||||
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
|
||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitor
|
||||
@@ -141,8 +144,10 @@ abstract class AbstractDiagnosticCollectorVisitor(
|
||||
}
|
||||
|
||||
override fun visitProperty(property: FirProperty, data: Nothing?) {
|
||||
withAnnotationContainer(property) {
|
||||
visitWithDeclaration(property)
|
||||
withPotentialPropertyFromPrimaryConstructor(property) {
|
||||
withAnnotationContainer(property) {
|
||||
visitWithDeclaration(property)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,6 +447,21 @@ abstract class AbstractDiagnosticCollectorVisitor(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
inline fun <R> withPotentialPropertyFromPrimaryConstructor(property: FirProperty, block: () -> R): R {
|
||||
val existingContext = context
|
||||
property.correspondingValueParameterFromPrimaryConstructor?.let {
|
||||
it.lazyResolveToPhase(FirResolvePhase.ANNOTATION_ARGUMENTS)
|
||||
@OptIn(SymbolInternals::class)
|
||||
addSuppressedDiagnosticsToContext(it.fir)
|
||||
}
|
||||
return try {
|
||||
block()
|
||||
} finally {
|
||||
context = existingContext
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
private inline fun <R> suppressInlineFunctionBodyContext(block: () -> R): R {
|
||||
val oldInlineFunctionBodyContext = context.inlineFunctionBodyContext?.also {
|
||||
|
||||
Vendored
-18
@@ -1,18 +0,0 @@
|
||||
// DIAGNOSTICS: -ERROR_SUPPRESSION
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-66258
|
||||
|
||||
@RequiresOptIn
|
||||
annotation class Ann
|
||||
|
||||
class A(
|
||||
<!OPT_IN_MARKER_ON_WRONG_TARGET!>@get:Ann<!>
|
||||
@Suppress("OPT_IN_MARKER_ON_WRONG_TARGET")
|
||||
val s: String
|
||||
)
|
||||
|
||||
class B {
|
||||
@get:Ann
|
||||
@Suppress("OPT_IN_MARKER_ON_WRONG_TARGET")
|
||||
val s: String = ""
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// DIAGNOSTICS: -ERROR_SUPPRESSION
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-66258
|
||||
|
||||
Reference in New Issue
Block a user