K2: add proper catch parameter annotation targeting
In this commit we begin counting a catch parameter as both a local variable and a value parameter for the purpose of annotation targeting. #KT-61691 Fixed
This commit is contained in:
committed by
Space Team
parent
91aa679214
commit
ffd77850ef
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.analysis.checkers
|
|||||||
|
|
||||||
import com.intellij.lang.LighterASTNode
|
import com.intellij.lang.LighterASTNode
|
||||||
import org.jetbrains.kotlin.*
|
import org.jetbrains.kotlin.*
|
||||||
|
import org.jetbrains.kotlin.KtFakeSourceElementKind.DesugaredComponentFunctionCall
|
||||||
import org.jetbrains.kotlin.builtins.StandardNames.HASHCODE_NAME
|
import org.jetbrains.kotlin.builtins.StandardNames.HASHCODE_NAME
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
@@ -30,7 +31,6 @@ import org.jetbrains.kotlin.fir.resolve.*
|
|||||||
import org.jetbrains.kotlin.fir.resolve.providers.firProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.firProvider
|
||||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||||
import org.jetbrains.kotlin.fir.scopes.*
|
import org.jetbrains.kotlin.fir.scopes.*
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.declaredMemberScope
|
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.multipleDelegatesWithTheSameSignature
|
import org.jetbrains.kotlin.fir.scopes.impl.multipleDelegatesWithTheSameSignature
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||||
@@ -617,10 +617,10 @@ fun getActualTargetList(container: FirAnnotationContainer): AnnotationTargetList
|
|||||||
is FirProperty -> {
|
is FirProperty -> {
|
||||||
when {
|
when {
|
||||||
annotated.isLocal ->
|
annotated.isLocal ->
|
||||||
if (annotated.source?.kind == KtFakeSourceElementKind.DesugaredComponentFunctionCall) {
|
when {
|
||||||
TargetLists.T_DESTRUCTURING_DECLARATION
|
annotated.source?.kind == DesugaredComponentFunctionCall -> TargetLists.T_DESTRUCTURING_DECLARATION
|
||||||
} else {
|
annotated.isCatchParameter == true -> TargetLists.T_CATCH_PARAMETER
|
||||||
TargetLists.T_LOCAL_VARIABLE
|
else -> TargetLists.T_LOCAL_VARIABLE
|
||||||
}
|
}
|
||||||
annotated.isMember ->
|
annotated.isMember ->
|
||||||
if (annotated.source?.kind == KtFakeSourceElementKind.PropertyFromParameter) {
|
if (annotated.source?.kind == KtFakeSourceElementKind.PropertyFromParameter) {
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ annotation class FixCatchClass
|
|||||||
fun main() {
|
fun main() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
} catch (@FixCatchLocalVariable <!WRONG_ANNOTATION_TARGET!>@FixCatchValueParameter<!> <!WRONG_ANNOTATION_TARGET!>@FixCatchClass<!> e: Throwable) {
|
} catch (@FixCatchLocalVariable @FixCatchValueParameter <!WRONG_ANNOTATION_TARGET!>@FixCatchClass<!> e: Throwable) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ object AnnotationTargetLists {
|
|||||||
onlyWithUseSiteTarget(PROPERTY_SETTER, VALUE_PARAMETER)
|
onlyWithUseSiteTarget(PROPERTY_SETTER, VALUE_PARAMETER)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val T_CATCH_PARAMETER = targetList(LOCAL_VARIABLE, VALUE_PARAMETER)
|
||||||
|
|
||||||
val T_DESTRUCTURING_DECLARATION = targetList(DESTRUCTURING_DECLARATION)
|
val T_DESTRUCTURING_DECLARATION = targetList(DESTRUCTURING_DECLARATION)
|
||||||
|
|
||||||
private fun TargetListBuilder.propertyTargets(backingField: Boolean, delegate: Boolean) {
|
private fun TargetListBuilder.propertyTargets(backingField: Boolean, delegate: Boolean) {
|
||||||
|
|||||||
Reference in New Issue
Block a user