diff --git a/analysis/low-level-api-fir/testData/lazyResolve/classes/annotationWithArgumentInsideSuperTypeCallUnresolved.txt b/analysis/low-level-api-fir/testData/lazyResolve/classes/annotationWithArgumentInsideSuperTypeCallUnresolved.txt index 7ef6bdf3add..ee442496c68 100644 --- a/analysis/low-level-api-fir/testData/lazyResolve/classes/annotationWithArgumentInsideSuperTypeCallUnresolved.txt +++ b/analysis/low-level-api-fir/testData/lazyResolve/classes/annotationWithArgumentInsideSuperTypeCallUnresolved.txt @@ -36,7 +36,7 @@ FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved. SUPER_TYPES: FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved.kt - public? final? [ResolvedTo(SUPER_TYPES)] class MyClass : { + public? final? [ResolvedTo(SUPER_TYPES)] class MyClass : @[Unresolved](LAZY_EXPRESSION) { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=MyClass] constructor(): R|MyClass| { LAZY_super<> } @@ -45,7 +45,7 @@ FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved. TYPES: FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved.kt - public? final? [ResolvedTo(TYPES)] class MyClass : { + public? final? [ResolvedTo(TYPES)] class MyClass : @[Unresolved](LAZY_EXPRESSION) { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=MyClass] constructor(): R|MyClass| { LAZY_super<> } @@ -54,7 +54,7 @@ FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved. STATUS: FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved.kt - public final [ResolvedTo(STATUS)] class MyClass : { + public final [ResolvedTo(STATUS)] class MyClass : @[Unresolved](LAZY_EXPRESSION) { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=MyClass] constructor(): R|MyClass| { LAZY_super<> } @@ -63,7 +63,7 @@ FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved. EXPECT_ACTUAL_MATCHING: FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved.kt - public final [ResolvedTo(EXPECT_ACTUAL_MATCHING)] class MyClass : { + public final [ResolvedTo(EXPECT_ACTUAL_MATCHING)] class MyClass : @[Unresolved](LAZY_EXPRESSION) { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=MyClass] constructor(): R|MyClass| { LAZY_super<> } @@ -72,7 +72,7 @@ FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved. CONTRACTS: FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved.kt - public final [ResolvedTo(CONTRACTS)] class MyClass : { + public final [ResolvedTo(CONTRACTS)] class MyClass : @[Unresolved](LAZY_EXPRESSION) { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=MyClass] constructor(): R|MyClass| { LAZY_super<> } @@ -81,7 +81,7 @@ FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved. IMPLICIT_TYPES_BODY_RESOLVE: FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved.kt - public final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] class MyClass : { + public final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] class MyClass : @[Unresolved](LAZY_EXPRESSION) { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=MyClass] constructor(): R|MyClass| { LAZY_super<> } @@ -90,7 +90,7 @@ FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved. ANNOTATION_ARGUMENTS: FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved.kt - public final [ResolvedTo(ANNOTATION_ARGUMENTS)] class MyClass : { + public final [ResolvedTo(ANNOTATION_ARGUMENTS)] class MyClass : @[Types]() { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=MyClass] constructor(): R|MyClass| { LAZY_super<> } @@ -99,7 +99,7 @@ FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved. BODY_RESOLVE: FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved.kt - public final [ResolvedTo(BODY_RESOLVE)] class MyClass : { + public final [ResolvedTo(BODY_RESOLVE)] class MyClass : @[Types]() { public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=MyClass] constructor(): R|MyClass| { super() } @@ -108,7 +108,7 @@ FILE: [ResolvedTo(IMPORTS)] annotationWithArgumentInsideSuperTypeCallUnresolved. FILE RAW TO BODY: FILE: [ResolvedTo(BODY_RESOLVE)] annotationWithArgumentInsideSuperTypeCallUnresolved.kt - public final [ResolvedTo(BODY_RESOLVE)] class MyClass : { + public final [ResolvedTo(BODY_RESOLVE)] class MyClass : @[Types]() { public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=MyClass] constructor(): R|MyClass| { super() } diff --git a/analysis/low-level-api-fir/testData/lazyResolve/functions/unresolvedAnnotationOnFunctionType.txt b/analysis/low-level-api-fir/testData/lazyResolve/functions/unresolvedAnnotationOnFunctionType.txt index e1439a3013c..8bc12239a93 100644 --- a/analysis/low-level-api-fir/testData/lazyResolve/functions/unresolvedAnnotationOnFunctionType.txt +++ b/analysis/low-level-api-fir/testData/lazyResolve/functions/unresolvedAnnotationOnFunctionType.txt @@ -20,37 +20,37 @@ FILE: [ResolvedTo(IMPORTS)] unresolvedAnnotationOnFunctionType.kt TYPES: FILE: [ResolvedTo(IMPORTS)] unresolvedAnnotationOnFunctionType.kt - public? final? [ResolvedTo(TYPES)] fun foo([ResolvedTo(TYPES)] a: ): { LAZY_BLOCK } + public? final? [ResolvedTo(TYPES)] fun foo([ResolvedTo(TYPES)] a: @[Unresolved](Foo#) ): @[Unresolved](Foo#) { LAZY_BLOCK } STATUS: FILE: [ResolvedTo(IMPORTS)] unresolvedAnnotationOnFunctionType.kt - public final [ResolvedTo(STATUS)] fun foo([ResolvedTo(STATUS)] a: ): { LAZY_BLOCK } + public final [ResolvedTo(STATUS)] fun foo([ResolvedTo(STATUS)] a: @[Unresolved](Foo#) ): @[Unresolved](Foo#) { LAZY_BLOCK } EXPECT_ACTUAL_MATCHING: FILE: [ResolvedTo(IMPORTS)] unresolvedAnnotationOnFunctionType.kt - public final [ResolvedTo(EXPECT_ACTUAL_MATCHING)] fun foo([ResolvedTo(EXPECT_ACTUAL_MATCHING)] a: ): { LAZY_BLOCK } + public final [ResolvedTo(EXPECT_ACTUAL_MATCHING)] fun foo([ResolvedTo(EXPECT_ACTUAL_MATCHING)] a: @[Unresolved](Foo#) ): @[Unresolved](Foo#) { LAZY_BLOCK } CONTRACTS: FILE: [ResolvedTo(IMPORTS)] unresolvedAnnotationOnFunctionType.kt - public final [ResolvedTo(CONTRACTS)] fun foo([ResolvedTo(CONTRACTS)] a: ): { + public final [ResolvedTo(CONTRACTS)] fun foo([ResolvedTo(CONTRACTS)] a: @[Unresolved](Foo#) ): @[Unresolved](Foo#) { } IMPLICIT_TYPES_BODY_RESOLVE: FILE: [ResolvedTo(IMPORTS)] unresolvedAnnotationOnFunctionType.kt - public final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] fun foo([ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] a: ): { + public final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] fun foo([ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] a: @[Unresolved](Foo#) ): @[Unresolved](Foo#) { } ANNOTATION_ARGUMENTS: FILE: [ResolvedTo(IMPORTS)] unresolvedAnnotationOnFunctionType.kt - public final [ResolvedTo(ANNOTATION_ARGUMENTS)] fun foo([ResolvedTo(ANNOTATION_ARGUMENTS)] a: ): { + public final [ResolvedTo(ANNOTATION_ARGUMENTS)] fun foo([ResolvedTo(ANNOTATION_ARGUMENTS)] a: @[Types]() ): @[Types]() { } BODY_RESOLVE: FILE: [ResolvedTo(IMPORTS)] unresolvedAnnotationOnFunctionType.kt - public final [ResolvedTo(BODY_RESOLVE)] fun foo([ResolvedTo(BODY_RESOLVE)] a: ): { + public final [ResolvedTo(BODY_RESOLVE)] fun foo([ResolvedTo(BODY_RESOLVE)] a: @[Types]() ): @[Types]() { } FILE RAW TO BODY: FILE: [ResolvedTo(BODY_RESOLVE)] unresolvedAnnotationOnFunctionType.kt - public final [ResolvedTo(BODY_RESOLVE)] fun foo([ResolvedTo(BODY_RESOLVE)] a: ): { + public final [ResolvedTo(BODY_RESOLVE)] fun foo([ResolvedTo(BODY_RESOLVE)] a: @[Types]() ): @[Types]() { } diff --git a/analysis/low-level-api-fir/testData/lazyResolve/properties/unresolvedAnnotationOnPropertyType.txt b/analysis/low-level-api-fir/testData/lazyResolve/properties/unresolvedAnnotationOnPropertyType.txt index cb54b22326d..1b2acaf9531 100644 --- a/analysis/low-level-api-fir/testData/lazyResolve/properties/unresolvedAnnotationOnPropertyType.txt +++ b/analysis/low-level-api-fir/testData/lazyResolve/properties/unresolvedAnnotationOnPropertyType.txt @@ -25,40 +25,40 @@ FILE: [ResolvedTo(IMPORTS)] unresolvedAnnotationOnPropertyType.kt TYPES: FILE: [ResolvedTo(IMPORTS)] unresolvedAnnotationOnPropertyType.kt - public? final? [ResolvedTo(TYPES)] val prop: - public? [ResolvedTo(TYPES)] get(): + public? final? [ResolvedTo(TYPES)] val prop: @[Unresolved](Foo#) + public? [ResolvedTo(TYPES)] get(): @[Unresolved](Foo#) STATUS: FILE: [ResolvedTo(IMPORTS)] unresolvedAnnotationOnPropertyType.kt - public final [ResolvedTo(STATUS)] val prop: - public [ResolvedTo(STATUS)] get(): + public final [ResolvedTo(STATUS)] val prop: @[Unresolved](Foo#) + public [ResolvedTo(STATUS)] get(): @[Unresolved](Foo#) EXPECT_ACTUAL_MATCHING: FILE: [ResolvedTo(IMPORTS)] unresolvedAnnotationOnPropertyType.kt - public final [ResolvedTo(EXPECT_ACTUAL_MATCHING)] val prop: - public [ResolvedTo(EXPECT_ACTUAL_MATCHING)] get(): + public final [ResolvedTo(EXPECT_ACTUAL_MATCHING)] val prop: @[Unresolved](Foo#) + public [ResolvedTo(EXPECT_ACTUAL_MATCHING)] get(): @[Unresolved](Foo#) CONTRACTS: FILE: [ResolvedTo(IMPORTS)] unresolvedAnnotationOnPropertyType.kt - public final [ResolvedTo(CONTRACTS)] val prop: - public [ResolvedTo(CONTRACTS)] get(): + public final [ResolvedTo(CONTRACTS)] val prop: @[Unresolved](Foo#) + public [ResolvedTo(CONTRACTS)] get(): @[Unresolved](Foo#) IMPLICIT_TYPES_BODY_RESOLVE: FILE: [ResolvedTo(IMPORTS)] unresolvedAnnotationOnPropertyType.kt - public final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] val prop: - public [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] get(): + public final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] val prop: @[Unresolved](Foo#) + public [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] get(): @[Unresolved](Foo#) ANNOTATION_ARGUMENTS: FILE: [ResolvedTo(IMPORTS)] unresolvedAnnotationOnPropertyType.kt - public final [ResolvedTo(ANNOTATION_ARGUMENTS)] val prop: - public [ResolvedTo(ANNOTATION_ARGUMENTS)] get(): + public final [ResolvedTo(ANNOTATION_ARGUMENTS)] val prop: @[Types]() + public [ResolvedTo(ANNOTATION_ARGUMENTS)] get(): @[Types]() BODY_RESOLVE: FILE: [ResolvedTo(IMPORTS)] unresolvedAnnotationOnPropertyType.kt - public final [ResolvedTo(BODY_RESOLVE)] val prop: - public [ResolvedTo(BODY_RESOLVE)] get(): + public final [ResolvedTo(BODY_RESOLVE)] val prop: @[Types]() + public [ResolvedTo(BODY_RESOLVE)] get(): @[Types]() FILE RAW TO BODY: FILE: [ResolvedTo(BODY_RESOLVE)] unresolvedAnnotationOnPropertyType.kt - public final [ResolvedTo(BODY_RESOLVE)] val prop: - public [ResolvedTo(BODY_RESOLVE)] get(): + public final [ResolvedTo(BODY_RESOLVE)] val prop: @[Types]() + public [ResolvedTo(BODY_RESOLVE)] get(): @[Types]() diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index b99f56109fe..5bfab965d5e 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -1554,6 +1554,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/annotations/AnnotatedConstructorParams.kt"); } + @Test + @TestMetadata("AnnotatedErrorTypeRef.kt") + public void testAnnotatedErrorTypeRef() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotations/AnnotatedErrorTypeRef.kt"); + } + @Test @TestMetadata("annotatedExpressionInsideAnnotation.kt") public void testAnnotatedExpressionInsideAnnotation() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index ed6089547e0..8d373f046ed 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -1554,6 +1554,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/annotations/AnnotatedConstructorParams.kt"); } + @Test + @TestMetadata("AnnotatedErrorTypeRef.kt") + public void testAnnotatedErrorTypeRef() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotations/AnnotatedErrorTypeRef.kt"); + } + @Test @TestMetadata("annotatedExpressionInsideAnnotation.kt") public void testAnnotatedExpressionInsideAnnotation() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 6b51daca58b..112a4302bdf 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -1554,6 +1554,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/annotations/AnnotatedConstructorParams.kt"); } + @Test + @TestMetadata("AnnotatedErrorTypeRef.kt") + public void testAnnotatedErrorTypeRef() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotations/AnnotatedErrorTypeRef.kt"); + } + @Test @TestMetadata("annotatedExpressionInsideAnnotation.kt") public void testAnnotatedExpressionInsideAnnotation() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 91af4fc1aed..817f0844d7d 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -1554,6 +1554,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/annotations/AnnotatedConstructorParams.kt"); } + @Test + @TestMetadata("AnnotatedErrorTypeRef.kt") + public void testAnnotatedErrorTypeRef() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotations/AnnotatedErrorTypeRef.kt"); + } + @Test @TestMetadata("annotatedExpressionInsideAnnotation.kt") public void testAnnotatedExpressionInsideAnnotation() throws Exception { diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/CopyUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/CopyUtils.kt index 5f05ef35869..aed3244e4cd 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/CopyUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/CopyUtils.kt @@ -49,6 +49,7 @@ fun FirTypeRef.resolvedTypeFromPrototype( source = this@resolvedTypeFromPrototype.source ?: fallbackSource this.type = type diagnostic = type.diagnostic + annotations += this@resolvedTypeFromPrototype.annotations } } else { buildResolvedTypeRef { diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt index e55cd88d17a..5b2460b7596 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt @@ -412,6 +412,7 @@ fun FirTypeRef.withReplacedConeType( buildErrorTypeRef { source = newSource type = newType + annotations += this@withReplacedConeType.annotations diagnostic = newType.diagnostic } } else { diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt index 8b3de307ec5..50c09b46aab 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt @@ -282,6 +282,7 @@ open class PsiRawFirBuilder( diagnostic = ConeSyntaxDiagnostic( if (this@toFirOrErrorType == null) "Incomplete code" else "Conversion failed" ) + this@toFirOrErrorType?.extractAnnotationsTo(this) } // Here we accept lambda as receiver to prevent expression calculation in stub mode diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSpecificTypeResolverTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSpecificTypeResolverTransformer.kt index b13f4674823..d6112aeb87e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSpecificTypeResolverTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSpecificTypeResolverTransformer.kt @@ -120,6 +120,7 @@ class FirSpecificTypeResolverTransformer( if (resolvedType != null) { type = resolvedType } + annotations += functionTypeRef.annotations this.diagnostic = diagnostic ?: (resolvedType as? ConeErrorType)?.diagnostic ?: ConeSimpleDiagnostic("Unresolved function type: ${functionTypeRef.render()}") } @@ -188,6 +189,7 @@ class FirSpecificTypeResolverTransformer( delegatedTypeRef = typeRef type = resolvedType + annotations += typeRef.annotations val partiallyResolvedTypeRef = tryCalculatingPartiallyResolvedTypeRef(typeRef, scopeClassDeclaration) this.partiallyResolvedTypeRef = partiallyResolvedTypeRef diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt index 7039293938e..b0394c852d8 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt @@ -365,6 +365,7 @@ open class FirTypeResolveTransformer( val errorTypeRef = buildErrorTypeRef { source = originalTypeRef.source type = coneTypeFromCompilerRequiredPhase + annotations += originalTypeRef.annotations delegatedTypeRef = originalTypeRef.delegatedTypeRef diagnostic = ConeAmbiguouslyResolvedAnnotationFromPlugin( coneTypeFromCompilerRequiredPhase, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt index 7e42b21df1b..9938f1cf581 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt @@ -1236,12 +1236,14 @@ open class FirDeclarationsResolveTransformer( return when (this) { is FirImplicitTypeRef -> buildErrorTypeRef { diagnostic = ConeSimpleDiagnostic("No result type for initializer", DiagnosticKind.InferenceError) + annotations.addAll(this@toExpectedTypeRef.annotations) } is FirErrorTypeRef -> buildErrorTypeRef { diagnostic = this@toExpectedTypeRef.diagnostic this@toExpectedTypeRef.source?.fakeElement(KtFakeSourceElementKind.ImplicitTypeRef)?.let { source = it } + annotations.addAll(this@toExpectedTypeRef.annotations) } else -> { buildResolvedTypeRef { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt index 6f52c889a88..2b668ab5c0d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt @@ -293,6 +293,7 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT val actualSuperTypeRef = actualSuperType?.toFirResolvedTypeRef(superTypeRef.source, superTypeRef) ?: buildErrorTypeRef { source = superTypeRef.source diagnostic = ConeSimpleDiagnostic("Not a super type", DiagnosticKind.NotASupertype) + annotations = superTypeRef.annotations.toMutableList() } superReferenceContainer.resultType = actualSuperTypeRef.type superReference.replaceSuperTypeRef(actualSuperTypeRef) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorFunctionImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorFunctionImpl.kt index 9caf6651c2f..9c70779acb8 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorFunctionImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorFunctionImpl.kt @@ -58,7 +58,7 @@ internal class FirErrorFunctionImpl( override val typeParameters: List get() = emptyList() override var status: FirDeclarationStatus = FirResolvedDeclarationStatusImpl.DEFAULT_STATUS_FOR_STATUSLESS_DECLARATIONS - override var returnTypeRef: FirTypeRef = FirErrorTypeRefImpl(null, null, diagnostic) + override var returnTypeRef: FirTypeRef = FirErrorTypeRefImpl(null, MutableOrEmptyList.empty(), null, null, diagnostic) override val receiverParameter: FirReceiverParameter? get() = null override var controlFlowGraphReference: FirControlFlowGraphReference? = null diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorPropertyImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorPropertyImpl.kt index 0bb383ad371..1a356a4ee9c 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorPropertyImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorPropertyImpl.kt @@ -60,7 +60,7 @@ internal class FirErrorPropertyImpl( override val typeParameters: List get() = emptyList() override var status: FirDeclarationStatus = FirResolvedDeclarationStatusImpl.DEFAULT_STATUS_FOR_STATUSLESS_DECLARATIONS - override var returnTypeRef: FirTypeRef = FirErrorTypeRefImpl(null, null, diagnostic) + override var returnTypeRef: FirTypeRef = FirErrorTypeRefImpl(null, MutableOrEmptyList.empty(), null, null, diagnostic) override val receiverParameter: FirReceiverParameter? get() = null override val initializer: FirExpression? diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/builder/FirErrorTypeRefBuilder.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/builder/FirErrorTypeRefBuilder.kt index e6ce6349265..839c194007a 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/builder/FirErrorTypeRefBuilder.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/builder/FirErrorTypeRefBuilder.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.types.builder import org.jetbrains.kotlin.KtSourceElement import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder import org.jetbrains.kotlin.fir.builder.FirBuilderDsl +import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic import org.jetbrains.kotlin.fir.expressions.FirAnnotation import org.jetbrains.kotlin.fir.types.ConeKotlinType @@ -20,34 +21,22 @@ import kotlin.contracts.contract @FirBuilderDsl class FirErrorTypeRefBuilder : FirAnnotationContainerBuilder { override var source: KtSourceElement? = null + override var annotations: MutableList = mutableListOf() var type: ConeKotlinType? = null var delegatedTypeRef: FirTypeRef? = null var partiallyResolvedTypeRef: FirTypeRef? = null - lateinit var diagnostic: ConeDiagnostic override fun build(): FirErrorTypeRef { - val type = this.type - return if (type != null) { - FirErrorTypeRefImpl( - source, - type, - delegatedTypeRef, - diagnostic, - partiallyResolvedTypeRef = partiallyResolvedTypeRef, - ) - } else { - FirErrorTypeRefImpl( - source, - delegatedTypeRef, - diagnostic, - partiallyResolvedTypeRef = partiallyResolvedTypeRef, - ) - } + return FirErrorTypeRefImpl( + source, + annotations.toMutableOrEmpty(), + this.type, + delegatedTypeRef, + diagnostic, + partiallyResolvedTypeRef = partiallyResolvedTypeRef, + ) } - - @Deprecated("Modification of 'annotations' has no impact for FirErrorTypeRefBuilder", level = DeprecationLevel.HIDDEN) - override val annotations: MutableList = mutableListOf() } @OptIn(ExperimentalContracts::class) @@ -66,6 +55,7 @@ inline fun buildErrorTypeRefCopy(original: FirErrorTypeRef, init: FirErrorTypeRe val copyBuilder = FirErrorTypeRefBuilder() copyBuilder.source = original.source copyBuilder.type = original.type + copyBuilder.annotations = original.annotations.toMutableList() copyBuilder.delegatedTypeRef = original.delegatedTypeRef copyBuilder.diagnostic = original.diagnostic return copyBuilder.apply(init).build() diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirErrorTypeRefImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirErrorTypeRefImpl.kt index 55c8b10db58..ca951ce005d 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirErrorTypeRefImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirErrorTypeRefImpl.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.types.impl import org.jetbrains.kotlin.KtSourceElement import org.jetbrains.kotlin.fir.MutableOrEmptyList +import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic import org.jetbrains.kotlin.fir.expressions.FirAnnotation import org.jetbrains.kotlin.fir.types.ConeErrorType @@ -19,23 +20,13 @@ import org.jetbrains.kotlin.fir.visitors.transformInplace internal class FirErrorTypeRefImpl( override val source: KtSourceElement?, - override val type: ConeKotlinType, + override var annotations: MutableOrEmptyList, + typeOrNull: ConeKotlinType?, override var delegatedTypeRef: FirTypeRef?, override val diagnostic: ConeDiagnostic, override var partiallyResolvedTypeRef: FirTypeRef? = null, ) : FirErrorTypeRef() { - constructor( - source: KtSourceElement?, delegatedTypeRef: FirTypeRef?, diagnostic: ConeDiagnostic, - partiallyResolvedTypeRef: FirTypeRef? = null, - ) : this( - source, - ConeErrorType(diagnostic), - delegatedTypeRef, - diagnostic, - partiallyResolvedTypeRef, - ) - - override val annotations: MutableOrEmptyList = MutableOrEmptyList.empty() + override val type: ConeKotlinType = typeOrNull ?: ConeErrorType(diagnostic) override fun acceptChildren(visitor: FirVisitor, data: D) { annotations.forEach { it.accept(visitor, data) } @@ -48,7 +39,7 @@ internal class FirErrorTypeRefImpl( } override fun replaceAnnotations(newAnnotations: List) { - throw AssertionError("Replacing annotations in FirErrorTypeRefImpl is not supported") + annotations = newAnnotations.toMutableOrEmpty() } override fun transformAnnotations(transformer: FirTransformer, data: D): FirErrorTypeRefImpl { diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt index 25d8874c8ec..1e4bf53fe71 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt @@ -307,7 +307,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator() "getter", "setter", withGetter = true ) - default("returnTypeRef", "FirErrorTypeRefImpl(null, null, diagnostic)") + default("returnTypeRef", "FirErrorTypeRefImpl(null, MutableOrEmptyList.empty(), null, null, diagnostic)") useTypes(errorTypeRefImplType) } @@ -536,7 +536,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator() impl(errorFunction) { defaultNull("receiverParameter", "body", withGetter = true) - default("returnTypeRef", "FirErrorTypeRefImpl(null, null, diagnostic)") + default("returnTypeRef", "FirErrorTypeRefImpl(null, MutableOrEmptyList.empty(), null, null, diagnostic)") useTypes(errorTypeRefImplType) } diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedErrorTypeRef.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotatedErrorTypeRef.fir.kt new file mode 100644 index 00000000000..c056695e649 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedErrorTypeRef.fir.kt @@ -0,0 +1,11 @@ +// ISSUE: KT-62447, KT-62628 +// FIR_DUMP + +fun main() { + val x: @SinceKotlin("2.0") +} + +@Target(AnnotationTarget.TYPE) +annotation class Anno + +val prop: @Anno Foo? = null diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedErrorTypeRef.fir.txt b/compiler/testData/diagnostics/tests/annotations/AnnotatedErrorTypeRef.fir.txt new file mode 100644 index 00000000000..b521e08321b --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedErrorTypeRef.fir.txt @@ -0,0 +1,12 @@ +FILE: AnnotatedErrorTypeRef.fir.kt + public final fun main(): R|kotlin/Unit| { + lval x: @R|kotlin/SinceKotlin|(version = String(2.0)) + } + @R|kotlin/annotation/Target|(allowedTargets = vararg(Q|kotlin/annotation/AnnotationTarget|.R|kotlin/annotation/AnnotationTarget.TYPE|)) public final annotation class Anno : R|kotlin/Annotation| { + public constructor(): R|Anno| { + super() + } + + } + public final val prop: @R|Anno|() = Null(null) + public get(): @R|Anno|() diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedErrorTypeRef.kt b/compiler/testData/diagnostics/tests/annotations/AnnotatedErrorTypeRef.kt new file mode 100644 index 00000000000..4eef9e7560a --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedErrorTypeRef.kt @@ -0,0 +1,11 @@ +// ISSUE: KT-62447, KT-62628 +// FIR_DUMP + +fun main() { + val x: @SinceKotlin("2.0") +} + +@Target(AnnotationTarget.TYPE) +annotation class Anno + +val prop: @Anno Foo? = null diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 284f920b222..920401760fd 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -1554,6 +1554,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/annotations/AnnotatedConstructorParams.kt"); } + @Test + @TestMetadata("AnnotatedErrorTypeRef.kt") + public void testAnnotatedErrorTypeRef() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotations/AnnotatedErrorTypeRef.kt"); + } + @Test @TestMetadata("annotatedExpressionInsideAnnotation.kt") public void testAnnotatedExpressionInsideAnnotation() throws Exception { diff --git a/plugins/fir-plugin-prototype/testData/diagnostics/functionalTypes/ambigousKinds.fir.txt b/plugins/fir-plugin-prototype/testData/diagnostics/functionalTypes/ambigousKinds.fir.txt index 23f42af9e21..c6ef55416ce 100644 --- a/plugins/fir-plugin-prototype/testData/diagnostics/functionalTypes/ambigousKinds.fir.txt +++ b/plugins/fir-plugin-prototype/testData/diagnostics/functionalTypes/ambigousKinds.fir.txt @@ -1,3 +1,3 @@ FILE: ambigousKinds.kt - public final fun incorrect(block: ): R|kotlin/Unit| { + public final fun incorrect(block: @R|org/jetbrains/kotlin/fir/plugin/MyComposable|() ): R|kotlin/Unit| { }