diff --git a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantReturnUnitTypeChecker.kt b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantReturnUnitTypeChecker.kt index 292a07200ae..f066a61e842 100644 --- a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantReturnUnitTypeChecker.kt +++ b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantReturnUnitTypeChecker.kt @@ -5,7 +5,7 @@ interface I { } class A { - fun too(): @Annotation Unit {} + fun too(): @Annotation Unit {} fun foo(): Unit { diff --git a/compiler/fir/analysis-tests/testData/resolve/multifile/Annotations.kt b/compiler/fir/analysis-tests/testData/resolve/multifile/Annotations.kt index edf9d585c88..2dba6a94475 100644 --- a/compiler/fir/analysis-tests/testData/resolve/multifile/Annotations.kt +++ b/compiler/fir/analysis-tests/testData/resolve/multifile/Annotations.kt @@ -30,7 +30,7 @@ abstract class First { } @WithString("xyz") -class Second(val y: Char) : @WithInt(0) First() { +class Second(val y: Char) : @WithInt(0) First() { override fun foo(arg: Double) { } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirAnnotationHelpers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirAnnotationHelpers.kt index 9737c0fe220..75a532b4754 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirAnnotationHelpers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirAnnotationHelpers.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.declarations.FirAnnotatedDeclaration import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference +import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.types.ConeClassLikeType import org.jetbrains.kotlin.fir.types.FirErrorTypeRef @@ -40,12 +41,14 @@ private val defaultAnnotationTargets = KotlinTarget.DEFAULT_TARGET_SET fun FirAnnotationCall.getAllowedAnnotationTargets(session: FirSession): Set { if (annotationTypeRef is FirErrorTypeRef) return KotlinTarget.values().toSet() - val annotationClass = (this.annotationTypeRef.coneType as? ConeClassLikeType)?.lookupTag?.toSymbol(session)?.fir as? FirRegularClass + val annotationClass = (this.annotationTypeRef.coneType as? ConeClassLikeType) + ?.fullyExpandedType(session)?.lookupTag?.toSymbol(session)?.fir as? FirRegularClass return annotationClass?.getAllowedAnnotationTargets() ?: defaultAnnotationTargets } fun FirRegularClass.getAllowedAnnotationTargets(): Set { val targetAnnotation = getTargetAnnotation() ?: return defaultAnnotationTargets + if (targetAnnotation.argumentList.arguments.isEmpty()) return emptySet() val arguments = when (val targetArgument = targetAnnotation.findSingleArgumentByName(TARGET_PARAMETER_NAME)) { is FirVarargArgumentsExpression -> targetArgument.arguments is FirArrayOfCall -> targetArgument.arguments diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirTypeAnnotationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirTypeAnnotationChecker.kt new file mode 100644 index 00000000000..44d6ba1c542 --- /dev/null +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirTypeAnnotationChecker.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.analysis.checkers.type + +import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget +import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.checkers.getAllowedAnnotationTargets +import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors +import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn +import org.jetbrains.kotlin.fir.analysis.diagnostics.withSuppressedDiagnostics +import org.jetbrains.kotlin.fir.types.FirTypeRef + +object FirTypeAnnotationChecker : FirTypeRefChecker() { + override fun check(typeRef: FirTypeRef, context: CheckerContext, reporter: DiagnosticReporter) { + for (annotation in typeRef.annotations) { + withSuppressedDiagnostics(annotation, context) { + val annotationTargets = annotation.getAllowedAnnotationTargets(context.session) + if (KotlinTarget.TYPE !in annotationTargets) { + val useSiteTarget = annotation.useSiteTarget + if (useSiteTarget == null || KotlinTarget.USE_SITE_MAPPING[useSiteTarget] !in annotationTargets) { + reporter.reportOn(annotation.source, FirErrors.WRONG_ANNOTATION_TARGET, "type usage", context) + } + } + } + } + } +} diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollectorVisitor.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollectorVisitor.kt index 1f8a78aaada..3fa25efa178 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollectorVisitor.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollectorVisitor.kt @@ -171,6 +171,7 @@ abstract class AbstractDiagnosticCollectorVisitor( if (resolvedTypeRef.type is ConeClassErrorType) { super.visitResolvedTypeRef(resolvedTypeRef, data) } + if (resolvedTypeRef.source?.kind is FirFakeSourceElementKind) return resolvedTypeRef.delegatedTypeRef?.accept(this, data) } diff --git a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CommonTypeCheckers.kt b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CommonTypeCheckers.kt index a5ca03979b4..f1ef43cb18d 100644 --- a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CommonTypeCheckers.kt +++ b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CommonTypeCheckers.kt @@ -5,18 +5,14 @@ package org.jetbrains.kotlin.fir.checkers -import org.jetbrains.kotlin.fir.analysis.cfa.AbstractFirPropertyInitializationChecker -import org.jetbrains.kotlin.fir.analysis.cfa.FirCallsEffectAnalyzer -import org.jetbrains.kotlin.fir.analysis.cfa.FirPropertyInitializationAnalyzer -import org.jetbrains.kotlin.fir.analysis.cfa.FirReturnsImpliesAnalyzer -import org.jetbrains.kotlin.fir.analysis.checkers.cfa.FirControlFlowChecker -import org.jetbrains.kotlin.fir.analysis.checkers.declaration.* import org.jetbrains.kotlin.fir.analysis.checkers.type.FirSuspendModifierChecker +import org.jetbrains.kotlin.fir.analysis.checkers.type.FirTypeAnnotationChecker import org.jetbrains.kotlin.fir.analysis.checkers.type.FirTypeRefChecker import org.jetbrains.kotlin.fir.analysis.checkers.type.TypeCheckers object CommonTypeCheckers : TypeCheckers() { override val typeRefCheckers: Set = setOf( - FirSuspendModifierChecker + FirTypeAnnotationChecker, + FirSuspendModifierChecker, ) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt index a1bd1aa4dd8..fc5c1fc9fa5 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt @@ -323,7 +323,8 @@ private fun FirTypeRef.hideLocalTypeIfNeeded( } val superType = firClass.superTypeRefs.single() if (superType is FirResolvedTypeRef) { - return superType + val newKind = source?.kind + return if (newKind is FirFakeSourceElementKind) superType.copyWithNewSourceKind(newKind) else superType } } return this diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedTryCatch.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotatedTryCatch.fir.kt new file mode 100644 index 00000000000..f648299f28d --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedTryCatch.fir.kt @@ -0,0 +1,9 @@ +annotation class My + +fun foo(arg: Int): Int { + try { + return 1 / (arg - arg) + } catch (e: @My Exception) { + return -1 + } +} diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedTryCatch.kt b/compiler/testData/diagnostics/tests/annotations/AnnotatedTryCatch.kt index de5ebc35adb..e98b5122708 100644 --- a/compiler/testData/diagnostics/tests/annotations/AnnotatedTryCatch.kt +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedTryCatch.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL annotation class My fun foo(arg: Int): Int { diff --git a/compiler/testData/diagnostics/tests/annotations/annotationOnParameterInFunctionType.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationOnParameterInFunctionType.fir.kt index 63606691a1c..4b86f649e7f 100644 --- a/compiler/testData/diagnostics/tests/annotations/annotationOnParameterInFunctionType.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/annotationOnParameterInFunctionType.fir.kt @@ -12,7 +12,7 @@ fun inParamNested(fn1: (fn2: (@Ann n: Int)->Unit)->Unit) {} fun inReturn(): (@Ann x: Int)->Unit = {} -class A : (@Ann Int)->Unit { +class A : (@Ann Int)->Unit { override fun invoke(p1: Int) { var lambda: (@Ann x: Int)->Unit = {} } diff --git a/compiler/testData/diagnostics/tests/annotations/annotationsOnNullableTypes.fir.kt b/compiler/testData/diagnostics/tests/annotations/annotationsOnNullableTypes.fir.kt deleted file mode 100644 index 840cb49a5de..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/annotationsOnNullableTypes.fir.kt +++ /dev/null @@ -1,44 +0,0 @@ -//!DIAGNOSTICS: -UNUSED_PARAMETER - -@Target(AnnotationTarget.TYPE) -annotation class a - -@Target(AnnotationTarget.TYPE) -annotation class b(val i: Int) - -annotation class c - -fun foo(i: @a Int?) {} - -fun foo(l: List<@a Int?>) {} - -fun @a Int?.bar() {} - -val baz: @a Int? = 1 - - -fun foo1(i: @b(1) Int?) {} - -fun foo1(l: List<@b(1) Int?>) {} - -fun @b(1) Int?.bar1() {} - -val baz1: @b(1) Int? = 1 - - -fun foo2(i: @[a b(1)] Int?) {} - -fun foo2(l: List<@[a b(1)] Int?>) {} - -fun @[a b(1)] Int?.bar2() {} - -val baz2: @[a b(1)] Int? = 1 - - -fun foo3(i: @c Int?) {} - -fun foo3(l: List<@c Int?>) {} - -fun @c Int?.bar3() {} - -val baz3: @c Int? = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/annotationsOnNullableTypes.kt b/compiler/testData/diagnostics/tests/annotations/annotationsOnNullableTypes.kt index abdf28f326c..c9c219adfd9 100644 --- a/compiler/testData/diagnostics/tests/annotations/annotationsOnNullableTypes.kt +++ b/compiler/testData/diagnostics/tests/annotations/annotationsOnNullableTypes.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL //!DIAGNOSTICS: -UNUSED_PARAMETER @Target(AnnotationTarget.TYPE) diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/annotation.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/annotation.fir.kt deleted file mode 100644 index bc74bf27ea1..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/annotation.fir.kt +++ /dev/null @@ -1,20 +0,0 @@ -@Target(AnnotationTarget.ANNOTATION_CLASS) annotation class base - -@base annotation class derived - -@base class correct(@base val x: Int) { - @base constructor(): this(0) -} - -@base enum class My { - @base FIRST, - @base SECOND -} - -@base fun foo(@base y: @base Int): Int { - @base fun bar(@base z: @base Int) = z + 1 - @base val local = bar(y) - return local -} - -@base val z = 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/annotation.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/annotation.kt index 6da9a55ee10..eb58ab58d59 100644 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/annotation.kt +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/annotation.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL @Target(AnnotationTarget.ANNOTATION_CLASS) annotation class base @base annotation class derived diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/classifier.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/classifier.fir.kt deleted file mode 100644 index 2c87197e03d..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/classifier.fir.kt +++ /dev/null @@ -1,21 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -@Target(AnnotationTarget.CLASS) annotation class base - -@base annotation class derived - -@base class correct(@base val x: Int, @base w: @base Int) { - @base constructor(): this(0, 0) -} - -@base enum class My @base constructor() { - @base FIRST, - @base SECOND -} - -@base fun foo(@base y: @base Int): Int { - @base fun bar(@base z: @base Int) = z + 1 - @base val local = bar(y) - return local -} - -@base val z = 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/classifier.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/classifier.kt index 348832ec0df..3737bfa0c4c 100644 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/classifier.kt +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/classifier.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER @Target(AnnotationTarget.CLASS) annotation class base diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/constructor.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/constructor.fir.kt deleted file mode 100644 index 8730a0d6e25..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/constructor.fir.kt +++ /dev/null @@ -1,20 +0,0 @@ -@Target(AnnotationTarget.CONSTRUCTOR) annotation class base - -@base annotation class derived - -@base class correct(@base val x: Int) { - @base constructor(): this(0) -} - -@base enum class My @base constructor() { - @base FIRST, - @base SECOND -} - -@base fun foo(@base y: @base Int): Int { - @base fun bar(@base z: @base Int) = z + 1 - @base val local = bar(y) - return local -} - -@base val z = 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/constructor.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/constructor.kt index c08fe661587..7aad78a0002 100644 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/constructor.kt +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/constructor.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL @Target(AnnotationTarget.CONSTRUCTOR) annotation class base @base annotation class derived diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/empty.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/empty.fir.kt deleted file mode 100644 index ca56a70c52c..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/empty.fir.kt +++ /dev/null @@ -1,21 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -@Target() annotation class empty - -@empty annotation class derived - -@empty class correct(@empty val x: Int, @empty w: @empty Int) { - @empty constructor(): this(0, 0) -} - -@empty enum class My @empty constructor() { - @empty FIRST, - @empty SECOND -} - -@empty fun foo(@empty y: @empty Int): Int { - @empty fun bar(@empty z: @empty Int) = z + 1 - @empty val local = bar(y) - return local -} - -@empty val z = @empty 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/empty.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/empty.kt index be3b5682d8f..1a97f21067a 100644 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/empty.kt +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/empty.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER @Target() annotation class empty diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/function.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/function.fir.kt deleted file mode 100644 index 419a05e7b33..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/function.fir.kt +++ /dev/null @@ -1,22 +0,0 @@ -@Target(AnnotationTarget.FUNCTION) annotation class base - -@base annotation class derived - -@base class correct(@base val x: Int) { - @base constructor(): this(0) - - @base public fun baz() {} -} - -@base enum class My @base constructor() { - @base FIRST, - @base SECOND -} - -@base fun foo(@base y: @base Int): Int { - @base fun bar(@base z: @base Int) = z + 1 - @base val local = bar(y) - return local -} - -@base val z = 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/function.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/function.kt index e019bee39c7..3590f017c0f 100644 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/function.kt +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/function.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL @Target(AnnotationTarget.FUNCTION) annotation class base @base annotation class derived diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.fir.kt index 12abd2c8ec1..07cc37dcad3 100644 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.fir.kt @@ -5,7 +5,7 @@ annotation class special @Target(AnnotationTarget.TYPE) annotation class base -fun transform(i: Int, tr: (@special Int) -> Int): Int = @special tr(@special i) +fun transform(i: Int, tr: (@special Int) -> Int): Int = @special tr(@special i) fun foo(i: Int): Int { val j = @special i + 1 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.fir.kt deleted file mode 100644 index 6e4d55e9671..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.fir.kt +++ /dev/null @@ -1,21 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -@Target(AnnotationTarget.INIT) annotation class incorrect - -@incorrect annotation class derived - -@incorrect class correct(@incorrect val x: Int, @incorrect w: @incorrect Int) { - @incorrect constructor(): this(0, 0) -} - -@incorrect enum class My @incorrect constructor() { - @incorrect FIRST, - @incorrect SECOND -} - -@incorrect fun foo(@incorrect y: @incorrect Int): Int { - @incorrect fun bar(@incorrect z: @incorrect Int) = z + 1 - @incorrect val local = bar(y) - return local -} - -@incorrect val z = @incorrect 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.kt index 5cfa806c340..153a1a248bd 100644 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.kt +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER @Target(AnnotationTarget.INIT) annotation class incorrect diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/java.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/java.fir.kt index 7a9ae6c9a06..0f6cb7c2657 100644 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/java.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/java.fir.kt @@ -64,15 +64,15 @@ import test.AnnotationTargets.* @base @meta @type @method @multiple class KClass( @base @fieldann @parameter val y: - @base @type Int) { + @base @type Int) { @base @multiple @fieldann @local val x = 0 @method @konstructor @type get @base @method @multiple @konstructor fun foo(@parameter @type i: - @base @multiple Int - ): @fieldann @parameter Int { + @base @multiple Int + ): @fieldann @parameter Int { @local @base @multiple @fieldann val j = i + 1 @base @multiple return j diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/local.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/local.fir.kt deleted file mode 100644 index 059684d7a2e..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/local.fir.kt +++ /dev/null @@ -1,20 +0,0 @@ -@Target(AnnotationTarget.LOCAL_VARIABLE) annotation class base - -@base annotation class derived - -@base class correct(@base val x: Int) { - @base constructor(): this(0) -} - -@base enum class My { - @base FIRST, - @base SECOND -} - -@base fun foo(@base y: @base Int): Int { - @base fun bar(@base z: @base Int) = z + 1 - @base val local = bar(y) - return local -} - -@base val z = 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/local.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/local.kt index 9b158213996..df766b5fbc2 100644 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/local.kt +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/local.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL @Target(AnnotationTarget.LOCAL_VARIABLE) annotation class base @base annotation class derived diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/property.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/property.fir.kt deleted file mode 100644 index d3c4c2ccf92..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/property.fir.kt +++ /dev/null @@ -1,21 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -@Target(AnnotationTarget.PROPERTY) annotation class base - -@base annotation class derived - -@base class correct(@base val x: Int, @base w: Int) { - @base constructor(): this(0, 0) -} - -@base enum class My { - @base FIRST, - @base SECOND -} - -@base fun foo(@base y: @base Int): Int { - @base fun bar(@base z: @base Int) = z + 1 - @base val local = bar(y) - return local -} - -@base val z = 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/property.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/property.kt index 7a76166d837..d13f1edf979 100644 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/property.kt +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/property.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER @Target(AnnotationTarget.PROPERTY) annotation class base diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/returntype.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/returntype.fir.kt deleted file mode 100644 index fc73f675e77..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/returntype.fir.kt +++ /dev/null @@ -1,9 +0,0 @@ -annotation class base - -@Target(AnnotationTarget.TYPE) -annotation class typed - -@base class My(val x: @base @typed Int, y: @base @typed Int) { - val z: @base @typed Int = y - fun foo(): @base @typed Int = z -} diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/returntype.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/returntype.kt index bbb615faefe..a0130adaf4e 100644 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/returntype.kt +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/returntype.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL annotation class base @Target(AnnotationTarget.TYPE) diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/typeParams.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/typeParams.fir.kt index 991faa0f3d1..997215c2e9c 100644 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/typeParams.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/typeParams.fir.kt @@ -26,10 +26,10 @@ class Class2 { @A fun foo() {} @A class D -fun foo(i: @A Int) { +fun foo(i: @A Int) { @A val i = 1 } -fun test(t: @A T): T = t +fun test(t: @A T): T = t @Target(AnnotationTarget.TYPE) diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.fir.kt deleted file mode 100644 index 0ac291e9e92..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.fir.kt +++ /dev/null @@ -1,10 +0,0 @@ -annotation class base - -val x: List<@base String>? = null - -val y: List<@[base] String>? = null - -@Target(AnnotationTarget.TYPE) -annotation class typeAnn - -fun foo(list: List<@typeAnn Int>) = list \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.kt index fff0fa6333f..884821d8080 100644 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.kt +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL annotation class base val x: List<@base String>? = null diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.fir.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.fir.kt deleted file mode 100644 index 4d17bde22a1..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.fir.kt +++ /dev/null @@ -1,21 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -@Target(AnnotationTarget.VALUE_PARAMETER) annotation class base - -@base annotation class derived - -@base class correct(@base val x: Int, @base w: Int) { - @base constructor(): this(0, 0) -} - -@base enum class My { - @base FIRST, - @base SECOND -} - -@base fun foo(@base y: @base Int): Int { - @base fun bar(@base z: @base Int) = z + 1 - @base val local = bar(y) - return local -} - -@base val z = 0 diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.kt index 2fe05bf5d97..176a22f64cc 100644 --- a/compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.kt +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER @Target(AnnotationTarget.VALUE_PARAMETER) annotation class base diff --git a/compiler/testData/diagnostics/tests/annotations/typeUse/nonTypeUseAnnotationOnType.fir.kt b/compiler/testData/diagnostics/tests/annotations/typeUse/nonTypeUseAnnotationOnType.fir.kt deleted file mode 100644 index 8bf69fa81ce..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/typeUse/nonTypeUseAnnotationOnType.fir.kt +++ /dev/null @@ -1,22 +0,0 @@ -// !LANGUAGE: +ProperCheckAnnotationsTargetInTypeUsePositions -// ISSUE: KT-28449 - -@Target(AnnotationTarget.PROPERTY_GETTER) -annotation class Ann - -abstract class Foo : @Ann Any() - -abstract class Bar - -fun test_1(a: Any) { - if (a is @Ann String) return -} - -open class TypeToken -val test_2 = object : TypeToken<@Ann String>() {} - -fun test_3(a: Any) { - a as @Ann Int -} - -fun test_4() where T : @Ann Any, T : @Ann CharSequence {} diff --git a/compiler/testData/diagnostics/tests/annotations/typeUse/nonTypeUseAnnotationOnType.kt b/compiler/testData/diagnostics/tests/annotations/typeUse/nonTypeUseAnnotationOnType.kt index 9420a410dbb..b0deecb09f1 100644 --- a/compiler/testData/diagnostics/tests/annotations/typeUse/nonTypeUseAnnotationOnType.kt +++ b/compiler/testData/diagnostics/tests/annotations/typeUse/nonTypeUseAnnotationOnType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +ProperCheckAnnotationsTargetInTypeUsePositions // ISSUE: KT-28449 diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992.fir.kt index 9f9e6edc898..4110a6c4112 100644 --- a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992.fir.kt @@ -6,4 +6,4 @@ annotation class Ann class E : @field:Ann @get:Ann @set:Ann @setparam:Ann Foo -interface G : @Ann Foo \ No newline at end of file +interface G : @Ann Foo diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.fir.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.fir.kt new file mode 100644 index 00000000000..16b31d9882e --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: +ProhibitUseSiteTargetAnnotationsOnSuperTypes + +interface Foo + +annotation class Ann + +class E : @field:Ann @get:Ann @set:Ann @setparam:Ann Foo + +interface G : @Ann Foo diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.kt index cbb6cd7774c..35d9da9d040 100644 --- a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.kt +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/kt23992_after.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // !LANGUAGE: +ProhibitUseSiteTargetAnnotationsOnSuperTypes interface Foo diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/11.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/11.fir.kt index 2f41746d89f..3f7e88a86aa 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/11.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/11.fir.kt @@ -6,22 +6,22 @@ annotation class Ann(val x: Int) // TESTCASE NUMBER: 1 -abstract class Foo : @Ann(10) Any() +abstract class Foo : @Ann(10) Any() // TESTCASE NUMBER: 2 -abstract class Bar +abstract class Bar@Ann(10) Any> // TESTCASE NUMBER: 3 fun case_3(a: Any) { - if (a is @Ann(10) String) return + if (a is @Ann(10) String) return } // TESTCASE NUMBER: 4 open class TypeToken -val case_4 = object : TypeToken<@Ann(10) String>() {} +val case_4 = object : TypeToken<@Ann(10) String>() {} // TESTCASE NUMBER: 5 fun case_5(a: Any) { - a as @Ann(10) Int + a as @Ann(10) Int } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/3.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/3.fir.kt index 2ac0950b2b2..e33b9733d06 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/3.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/3.fir.kt @@ -8,7 +8,7 @@ annotation class Ann(val x: Int) fun foo(i: Inv<@Ann(unresolved_reference) String>) {} // TESTCASE NUMBER: 2 -fun test(vararg a: @Ann(unresolved_reference) Any) {} +fun test(vararg a: @Ann(unresolved_reference) Any) {} // TESTCASE NUMBER: 3 class A(a: @Ann(unresolved_reference) T) diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/7.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/7.fir.kt index 6c991d298d1..2b0a070d581 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/7.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/7.fir.kt @@ -18,4 +18,4 @@ val case_1 = object : TypeToken<@Ann(unresolved_reference) String>() {} */ interface A -val case_2 = object: @Ann(unresolved_reference) A {} +val case_2 = object: @Ann(unresolved_reference) A {}