[Fir] get candidate from missed type args diagnostics in annotation call
Otherwise, navigation to unresolved reference is impossible ^ KTIJ-26441 In order to avoid duplicated diagnostic, wrapper is still used. Symbol collector is updated to retrieve symbols from that wrapper. Merge-request: KT-MR-11381 Merged-by: Anna Kozlova <Anna.Kozlova@jetbrains.com>
This commit is contained in:
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.toAnnotationClassId
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
|
||||
@@ -68,6 +69,7 @@ internal fun ConeDiagnostic.getCandidateSymbols(): Collection<FirBasedSymbol<*>>
|
||||
}
|
||||
is ConeDiagnosticWithCandidates -> candidateSymbols
|
||||
is ConeDiagnosticWithSymbol<*> -> listOf(symbol)
|
||||
is ConeStubDiagnostic -> original.getCandidateSymbols()
|
||||
else -> emptyList()
|
||||
}
|
||||
|
||||
|
||||
analysis/low-level-api-fir/testdata/getOrBuildFir/invalidCode/missedTypeArgumentsInAnnotationCall.kt
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtNameReferenceExpression
|
||||
package usage
|
||||
|
||||
annotation class B<T>
|
||||
|
||||
@<expr>B</expr>
|
||||
class A
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
KT element: KtNameReferenceExpression
|
||||
FIR element: FirErrorNamedReferenceImpl
|
||||
FIR source kind: KtRealSourceElementKind
|
||||
|
||||
FIR element rendered:
|
||||
<Wrong number of type arguments>#
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(IMPORTS)] missedTypeArgumentsInAnnotationCall.kt
|
||||
package usage
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] annotation class B<[ResolvedTo(RAW_FIR)] T> : R|kotlin/Annotation| {
|
||||
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=B] constructor<[ResolvedTo(RAW_FIR)] T>(): R|usage/B<T>| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
}
|
||||
@<ERROR TYPE REF: Wrong number of type arguments>[Types]() public final [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] class A : R|kotlin/Any| {
|
||||
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=A] constructor(): R|usage/A| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -907,6 +907,12 @@ public class OutOfContentRootGetOrBuildFirTestGenerated extends AbstractOutOfCon
|
||||
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/invalidCode/javaClassLiteral.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missedTypeArgumentsInAnnotationCall.kt")
|
||||
public void testMissedTypeArgumentsInAnnotationCall() throws Exception {
|
||||
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/invalidCode/missedTypeArgumentsInAnnotationCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("secondaryConstructor.kt")
|
||||
public void testSecondaryConstructor() throws Exception {
|
||||
|
||||
+6
@@ -907,6 +907,12 @@ public class SourceGetOrBuildFirTestGenerated extends AbstractSourceGetOrBuildFi
|
||||
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/invalidCode/javaClassLiteral.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missedTypeArgumentsInAnnotationCall.kt")
|
||||
public void testMissedTypeArgumentsInAnnotationCall() throws Exception {
|
||||
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/invalidCode/missedTypeArgumentsInAnnotationCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("secondaryConstructor.kt")
|
||||
public void testSecondaryConstructor() throws Exception {
|
||||
|
||||
+6
@@ -687,6 +687,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/localInterfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missedTypeArgumentsInAnnotationCall.kt")
|
||||
public void testMissedTypeArgumentsInAnnotationCall() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/missedTypeArgumentsInAnnotationCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missingIteratorMissing.kt")
|
||||
public void testMissingIteratorMissing() throws Exception {
|
||||
|
||||
+6
@@ -687,6 +687,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/localInterfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missedTypeArgumentsInAnnotationCall.kt")
|
||||
public void testMissedTypeArgumentsInAnnotationCall() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/missedTypeArgumentsInAnnotationCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missingIteratorMissing.kt")
|
||||
public void testMissingIteratorMissing() throws Exception {
|
||||
|
||||
+6
@@ -687,6 +687,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/localInterfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missedTypeArgumentsInAnnotationCall.kt")
|
||||
public void testMissedTypeArgumentsInAnnotationCall() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/missedTypeArgumentsInAnnotationCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missingIteratorMissing.kt")
|
||||
public void testMissingIteratorMissing() throws Exception {
|
||||
|
||||
+6
@@ -687,6 +687,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/localInterfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missedTypeArgumentsInAnnotationCall.kt")
|
||||
public void testMissedTypeArgumentsInAnnotationCall() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/missedTypeArgumentsInAnnotationCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missingIteratorMissing.kt")
|
||||
public void testMissingIteratorMissing() throws Exception {
|
||||
|
||||
@@ -586,7 +586,10 @@ class FirCallResolver(
|
||||
callInfo,
|
||||
if (annotationClassSymbol != null) ConeIllegalAnnotationError(reference.name)
|
||||
//calleeReference and annotationTypeRef are both error nodes so we need to avoid doubling of the diagnostic report
|
||||
else ConeStubDiagnostic(ConeUnresolvedNameError(reference.name)),
|
||||
else ConeStubDiagnostic(
|
||||
//prefer diagnostic with symbol, e.g. to use the symbol during navigation in IDE
|
||||
(annotation.typeRef.coneType as? ConeErrorType)?.diagnostic as? ConeDiagnosticWithSymbol<*>
|
||||
?: ConeUnresolvedNameError(reference.name)),
|
||||
reference.source
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// FIR_IDENTICAL
|
||||
package usage
|
||||
|
||||
annotation class B<T>
|
||||
|
||||
@<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>B<!>
|
||||
class A
|
||||
Generated
+6
@@ -687,6 +687,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/localInterfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missedTypeArgumentsInAnnotationCall.kt")
|
||||
public void testMissedTypeArgumentsInAnnotationCall() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/missedTypeArgumentsInAnnotationCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("missingIteratorMissing.kt")
|
||||
public void testMissingIteratorMissing() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user