FIR: don't check annotations on returnTypeRefs that are not of real kind
This fixes an exception in FirAnnotationChecker where we tried to report repeated annotations on implicit type refs that have no source.
This commit is contained in:
committed by
Space Team
parent
c0961e91b8
commit
5a08d8da8d
+6
@@ -4870,6 +4870,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis
|
||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/removeOnAbstractMap.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("repeatedAnnotations.kt")
|
||||
public void testRepeatedAnnotations() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/repeatedAnnotations.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("runOnIntegerLiteral.kt")
|
||||
public void testRunOnIntegerLiteral() throws Exception {
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
FILE: test.kt
|
||||
public final fun <T> foo(bar: R|() -> T|): R|kotlin/Unit| {
|
||||
}
|
||||
@R|kotlin/annotation/Target|(allowedTargets = vararg(Q|kotlin/annotation/AnnotationTarget|.R|kotlin/annotation/AnnotationTarget.TYPE|)) public final annotation class Ann : R|kotlin/Annotation| {
|
||||
public constructor(): R|Ann| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
public final fun baz(): R|@R|Ann|() @R|Ann|() kotlin/String| {
|
||||
^baz String(12)
|
||||
}
|
||||
public final fun qux(): R|@R|SomeAnn|(value = Int(1)) @R|SomeAnn|(value = Int(2)) kotlin/String!| {
|
||||
^qux Q|Some|.R|/Some.foo|().R|SubstitutionOverride<kotlin/collections/MutableList.get: R|@R|SomeAnn|(value = Int(1)) @R|SomeAnn|(value = Int(2)) kotlin/String!|>|(Int(0))
|
||||
}
|
||||
public final fun test(): R|kotlin/Unit| {
|
||||
R|/foo|<R|@R|SomeAnn|(value = Int(1)) @R|SomeAnn|(value = Int(2)) kotlin/String!|>(foo@fun <anonymous>(): R|@R|SomeAnn|(value = Int(1)) @R|SomeAnn|(value = Int(2)) kotlin/String!| <inline=NoInline> {
|
||||
^ Q|Some|.R|/Some.foo|().R|SubstitutionOverride<kotlin/collections/MutableList.get: R|@R|SomeAnn|(value = Int(1)) @R|SomeAnn|(value = Int(2)) kotlin/String!|>|(Int(0))
|
||||
}
|
||||
)
|
||||
R|/foo|<R|@R|Ann|() @R|Ann|() kotlin/String|>(foo@fun <anonymous>(): R|@R|Ann|() @R|Ann|() kotlin/String| <inline=NoInline> {
|
||||
^ R|/baz|()
|
||||
}
|
||||
)
|
||||
R|/foo|<R|@R|SomeAnn|(value = Int(1)) @R|SomeAnn|(value = Int(2)) kotlin/String!|>(foo@fun <anonymous>(): R|@R|SomeAnn|(value = Int(1)) @R|SomeAnn|(value = Int(2)) kotlin/String!| <inline=NoInline> {
|
||||
^ R|/qux|()
|
||||
}
|
||||
)
|
||||
R|/foo|<R|@R|Ann|() @R|Ann|() kotlin/String|>(fun <anonymous>(): R|@R|Ann|() @R|Ann|() kotlin/String| <inline=NoInline> {
|
||||
^@foo String()
|
||||
}
|
||||
)
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
// FILE: Some.java
|
||||
import java.util.List;
|
||||
|
||||
public class Some {
|
||||
public static List<@SomeAnn(1) @SomeAnn(2) String> foo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: SomeAnn.java
|
||||
|
||||
@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE})
|
||||
public @interface SomeAnn {
|
||||
int value();
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.kt
|
||||
fun <T> foo(bar: () -> T) {
|
||||
|
||||
}
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class Ann
|
||||
|
||||
fun baz(): @Ann <!REPEATED_ANNOTATION!>@Ann<!> String = "12"
|
||||
fun qux() = Some.foo()[0]
|
||||
|
||||
fun test() {
|
||||
foo({ Some.foo()[0] })
|
||||
foo({ baz() })
|
||||
foo({ qux() })
|
||||
foo(fun(): @Ann <!REPEATED_ANNOTATION!>@Ann<!> String {
|
||||
return ""
|
||||
})
|
||||
}
|
||||
|
||||
+6
@@ -4870,6 +4870,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/removeOnAbstractMap.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("repeatedAnnotations.kt")
|
||||
public void testRepeatedAnnotations() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/repeatedAnnotations.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("runOnIntegerLiteral.kt")
|
||||
public void testRunOnIntegerLiteral() throws Exception {
|
||||
|
||||
+6
@@ -4870,6 +4870,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/removeOnAbstractMap.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("repeatedAnnotations.kt")
|
||||
public void testRepeatedAnnotations() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/repeatedAnnotations.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("runOnIntegerLiteral.kt")
|
||||
public void testRunOnIntegerLiteral() throws Exception {
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.KtRealSourceElementKind
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget.*
|
||||
@@ -70,7 +71,7 @@ object FirAnnotationChecker : FirBasicDeclarationChecker() {
|
||||
if (declaration is FirProperty) {
|
||||
checkRepeatedAnnotationsInProperty(declaration, context, reporter)
|
||||
} else if (declaration is FirCallableDeclaration) {
|
||||
if (declaration.source?.kind !is KtFakeSourceElementKind) {
|
||||
if (declaration.source?.kind is KtRealSourceElementKind && declaration.returnTypeRef.source?.kind is KtRealSourceElementKind) {
|
||||
checkRepeatedAnnotations(declaration.returnTypeRef.coneTypeSafe(), context, reporter)
|
||||
}
|
||||
} else if (declaration is FirTypeAlias) {
|
||||
|
||||
Reference in New Issue
Block a user