[K2] Disappeared UNSUPPORTED
Prohibit annotations for parameters in function type ^KT-59881
This commit is contained in:
committed by
Space Team
parent
f0f06ccf2e
commit
23bed574c1
+31
-5
@@ -6,18 +6,19 @@
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.type
|
||||
|
||||
import org.jetbrains.kotlin.*
|
||||
import org.jetbrains.kotlin.KtNodeTypes.ANNOTATION_ENTRY
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.diagnostics.valOrVarKeyword
|
||||
import org.jetbrains.kotlin.fir.FirFunctionTypeParameter
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.FirModifierList
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.getModifierList
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.syntax.FirSyntaxChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.types.FirFunctionTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtValVarKeywordOwner
|
||||
import org.jetbrains.kotlin.psi.psiUtil.children
|
||||
import org.jetbrains.kotlin.util.getChildren
|
||||
|
||||
object FirUnsupportedModifiersInFunctionTypeParameterChecker : FirFunctionalTypeParameterSyntaxChecker() {
|
||||
|
||||
@@ -25,9 +26,10 @@ object FirUnsupportedModifiersInFunctionTypeParameterChecker : FirFunctionalType
|
||||
element: FirFunctionTypeParameter,
|
||||
source: KtSourceElement,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
reporter: DiagnosticReporter,
|
||||
) {
|
||||
checkModifiers(source, reporter, context)
|
||||
checkAnnotations(source, reporter, context)
|
||||
checkValOrVarKeyword(source, reporter, context)
|
||||
}
|
||||
|
||||
@@ -61,4 +63,28 @@ object FirUnsupportedModifiersInFunctionTypeParameterChecker : FirFunctionalType
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun checkAnnotations(source: KtSourceElement, reporter: DiagnosticReporter, context: CheckerContext): Boolean {
|
||||
val commonModifiersList = source.getModifierList() ?: return true
|
||||
val annotationsSource = when (commonModifiersList) {
|
||||
is FirModifierList.FirLightModifierList -> {
|
||||
val tree = commonModifiersList.tree
|
||||
val children = commonModifiersList.modifierList.getChildren(tree)
|
||||
children.filter { it.tokenType == ANNOTATION_ENTRY }.map { it.toKtLightSourceElement(tree) }
|
||||
}
|
||||
is FirModifierList.FirPsiModifierList -> {
|
||||
val children = commonModifiersList.modifierList.node.children()
|
||||
children.filter { it.elementType == ANNOTATION_ENTRY }.map { KtRealPsiSourceElement(it.psi) }.toList()
|
||||
}
|
||||
}
|
||||
for (ann in annotationsSource) {
|
||||
reporter.reportOn(
|
||||
ann,
|
||||
FirErrors.UNSUPPORTED,
|
||||
"annotation on parameter in function type",
|
||||
context
|
||||
)
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
+9
-8
@@ -1,30 +1,31 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
annotation class Ann
|
||||
annotation class Ann2
|
||||
|
||||
fun f(@Ann x: Int) {}
|
||||
|
||||
val inVal: (@Ann x: Int)->Unit = {}
|
||||
val inVal: (<!UNSUPPORTED!>@Ann<!> <!UNSUPPORTED!>@Ann2<!> x: Int)->Unit = {}
|
||||
|
||||
fun inParam(fn: (@Ann x: Int)->Unit) {}
|
||||
fun inParam(fn: (<!UNSUPPORTED!>@Ann<!> x: Int)->Unit) {}
|
||||
|
||||
fun inParamNested(fn1: (fn2: (@Ann n: Int)->Unit)->Unit) {}
|
||||
fun inParamNested(fn1: (fn2: (<!UNSUPPORTED!>@Ann<!> n: Int)->Unit)->Unit) {}
|
||||
|
||||
fun inReturn(): (@Ann x: Int)->Unit = {}
|
||||
fun inReturn(): (<!UNSUPPORTED!>@Ann<!> x: Int)->Unit = {}
|
||||
|
||||
class A : (<!WRONG_ANNOTATION_TARGET!>@Ann<!> Int)->Unit {
|
||||
override fun invoke(p1: Int) {
|
||||
var lambda: (@Ann x: Int)->Unit = {}
|
||||
var lambda: (<!UNSUPPORTED!>@Ann<!> x: Int)->Unit = {}
|
||||
}
|
||||
|
||||
val prop: (@Ann x: Int)->Unit
|
||||
get(): (@Ann x: Int)->Unit = {}
|
||||
val prop: (<!UNSUPPORTED!>@Ann<!> x: Int)->Unit
|
||||
get(): (<!UNSUPPORTED!>@Ann<!> x: Int)->Unit = {}
|
||||
}
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class TypeAnn
|
||||
|
||||
val onType: (@TypeAnn A).(@Ann a: @TypeAnn A, @TypeAnn A)->@TypeAnn A? = <!INITIALIZER_TYPE_MISMATCH!>{ null }<!>
|
||||
val onType: (@TypeAnn A).(<!UNSUPPORTED!>@Ann<!> a: @TypeAnn A, @TypeAnn A)->@TypeAnn A? = <!INITIALIZER_TYPE_MISMATCH!>{ null }<!>
|
||||
|
||||
fun (@TypeAnn A).extFun(@Ann a: @TypeAnn A): @TypeAnn A? = null
|
||||
|
||||
|
||||
+2
-1
@@ -1,10 +1,11 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
annotation class Ann
|
||||
annotation class Ann2
|
||||
|
||||
fun f(@Ann x: Int) {}
|
||||
|
||||
val inVal: (<!UNSUPPORTED!>@Ann<!> x: Int)->Unit = {}
|
||||
val inVal: (<!UNSUPPORTED!>@Ann<!> <!UNSUPPORTED!>@Ann2<!> x: Int)->Unit = {}
|
||||
|
||||
fun inParam(fn: (<!UNSUPPORTED!>@Ann<!> x: Int)->Unit) {}
|
||||
|
||||
|
||||
+7
@@ -27,6 +27,13 @@ public final annotation class Ann : kotlin.Annotation {
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final annotation class Ann2 : kotlin.Annotation {
|
||||
public constructor Ann2()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) public final annotation class TypeAnn : kotlin.Annotation {
|
||||
public constructor TypeAnn()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
|
||||
Reference in New Issue
Block a user