[FIR] Add diagnostic when annotation argument is resolved ambiguously

Annotation arguments that are resolved in COMPILER_REQUIRED_ANNOTATIONS
phase are resolved again in ANNOTATION_ARGUMENTS phase. If they resolve
to a different symbol, report an error.

KT-56177
This commit is contained in:
Kirill Rakhman
2023-02-23 18:16:39 +01:00
committed by Space Team
parent 9dda5e4fcd
commit 2139914061
27 changed files with 253 additions and 5 deletions
@@ -1007,6 +1007,15 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirErrors.AMBIGUOUS_ANNOTATION_ARGUMENT) { firDiagnostic ->
AmbiguousAnnotationArgumentImpl(
firDiagnostic.a.map { firBasedSymbol ->
firSymbolBuilder.buildSymbol(firBasedSymbol)
},
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirJsErrors.WRONG_JS_QUALIFIER) { firDiagnostic ->
WrongJsQualifierImpl(
firDiagnostic as KtPsiDiagnostic,
@@ -728,6 +728,11 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
abstract val typeFromTypesPhase: KtType
}
abstract class AmbiguousAnnotationArgument : KtFirDiagnostic<PsiElement>() {
override val diagnosticClass get() = AmbiguousAnnotationArgument::class
abstract val symbols: List<KtSymbol>
}
abstract class WrongJsQualifier : KtFirDiagnostic<KtElement>() {
override val diagnosticClass get() = WrongJsQualifier::class
}
@@ -873,6 +873,12 @@ internal class PluginAnnotationAmbiguityImpl(
override val token: KtLifetimeToken,
) : KtFirDiagnostic.PluginAnnotationAmbiguity(), KtAbstractFirDiagnostic<PsiElement>
internal class AmbiguousAnnotationArgumentImpl(
override val symbols: List<KtSymbol>,
override val firDiagnostic: KtPsiDiagnostic,
override val token: KtLifetimeToken,
) : KtFirDiagnostic.AmbiguousAnnotationArgument(), KtAbstractFirDiagnostic<PsiElement>
internal class WrongJsQualifierImpl(
override val firDiagnostic: KtPsiDiagnostic,
override val token: KtLifetimeToken,
@@ -35874,6 +35874,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/annotations"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
}
@Test
@TestMetadata("annotationTargetResolvedAmbiguously.kt")
public void testAnnotationTargetResolvedAmbiguously() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/annotationTargetResolvedAmbiguously.kt");
}
@Test
@TestMetadata("annotationsTargetingLateinitAccessors.kt")
public void testAnnotationsTargetingLateinitAccessors() throws Exception {