FIR: Avoid propagation of @Exact annotation through elvis
This commit is contained in:
committed by
teamcityserver
parent
0d9ad62d4a
commit
7eb758fab1
+6
@@ -33179,6 +33179,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/defaultValueMustBeConstant.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("dontPropagateExact.kt")
|
||||
public void testDontPropagateExact() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/dontPropagateExact.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("explicitMetadata.kt")
|
||||
public void testExplicitMetadata() throws Exception {
|
||||
|
||||
+6
@@ -33179,6 +33179,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/defaultValueMustBeConstant.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("dontPropagateExact.kt")
|
||||
public void testDontPropagateExact() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/dontPropagateExact.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("explicitMetadata.kt")
|
||||
public void testExplicitMetadata() throws Exception {
|
||||
|
||||
+6
@@ -33179,6 +33179,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/defaultValueMustBeConstant.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("dontPropagateExact.kt")
|
||||
public void testDontPropagateExact() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/dontPropagateExact.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("explicitMetadata.kt")
|
||||
public void testExplicitMetadata() throws Exception {
|
||||
|
||||
+16
-1
@@ -332,7 +332,22 @@ class FirCallCompletionResultsWriterTransformer(
|
||||
type = substitutedType ?: initialType, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference,
|
||||
) ?: substitutedType
|
||||
|
||||
return withReplacedConeType(finalType)
|
||||
// This is probably a temporary hack, but it seems necessary because elvis has that attribute and it may leak further like
|
||||
// fun <E> foo() = materializeNullable<E>() ?: materialize<E>() // `foo` return type unexpectedly gets inferred to @Exact E
|
||||
//
|
||||
// In FE1.0, it's not necessary since the annotation for elvis have some strange form (see org.jetbrains.kotlin.resolve.descriptorUtil.AnnotationsWithOnly)
|
||||
// that is not propagated further.
|
||||
val withRemovedExactAttribute = finalType?.removeExactAttribute()
|
||||
|
||||
return withReplacedConeType(withRemovedExactAttribute)
|
||||
}
|
||||
|
||||
private fun ConeKotlinType.removeExactAttribute(): ConeKotlinType {
|
||||
if (attributes.contains(CompilerConeAttributes.Exact)) {
|
||||
return withAttributes(attributes.remove(CompilerConeAttributes.Exact), session.typeContext)
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
override fun transformSafeCallExpression(
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// FIR_IDENTICAL
|
||||
// FULL_JDK
|
||||
// SKIP_TXT
|
||||
package test
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
annotation class RunsInActiveStoreMode
|
||||
|
||||
val w1 = ""::class.java
|
||||
val w2 = ""::class.java
|
||||
|
||||
private fun <T : Annotation> foo(annotationClass: Class<T>) = w1.getAnnotation(annotationClass) ?: w2.getAnnotation(annotationClass)
|
||||
|
||||
fun main() {
|
||||
val x: Any = foo(RunsInActiveStoreMode::class.java)
|
||||
}
|
||||
Generated
+6
@@ -33275,6 +33275,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/defaultValueMustBeConstant.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("dontPropagateExact.kt")
|
||||
public void testDontPropagateExact() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/dontPropagateExact.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("explicitMetadata.kt")
|
||||
public void testExplicitMetadata() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user