[FIR] Fixed behavior of FirAnnotation.findArgumentByName for resolved annotations

The 'findArgumentByName' function was returning an invalid result for
annotation arguments with omitted argument name.

#KT-64276
This commit is contained in:
Anastasia.Nekrasova
2024-02-16 14:05:38 +02:00
committed by Space Team
parent bb8c7dd04c
commit d69240a2d5
5 changed files with 44 additions and 3 deletions
@@ -132,9 +132,11 @@ fun FirAnnotation.findArgumentByName(name: Name): FirExpression? {
return argument.expression
}
}
// I'm lucky today!
// TODO: this line is still needed. However it should be replaced with 'return null'
return arguments.singleOrNull()
// The condition is required for annotation arguments that are not fully resolved. For example, CompilerRequiredAnnotations.
// When the annotation is resolved, and we did not find an argument with the given name,
// there is no argument and we should return null.
return if (!resolved) arguments.firstOrNull() else null
}
fun FirAnnotation.getBooleanArgument(name: Name): Boolean? = getPrimitiveArgumentValue(name)
@@ -0,0 +1,21 @@
// FIR_IDENTICAL
// FILE: kotlin.kt
@file:OptIn(ExperimentalObjCName::class)
package kotlin.native
import kotlin.experimental.ExperimentalObjCName
fun interface BaseInterface {
@ObjCName(name = "close")
fun close()
}
open class BaseClass {
@ObjCName("close")
fun close() {
}
}
class DerivedClass : BaseClass(), BaseInterface {}
@@ -108,6 +108,12 @@ public class DiagnosticsNativeTestGenerated extends AbstractDiagnosticsNativeTes
runTest("compiler/testData/diagnostics/nativeTests/objCName5.kt");
}
@Test
@TestMetadata("objCNameWIthDifferentSwiftName.kt")
public void testObjCNameWIthDifferentSwiftName() {
runTest("compiler/testData/diagnostics/nativeTests/objCNameWIthDifferentSwiftName.kt");
}
@Test
@TestMetadata("objCNameWithTwoModules.kt")
public void testObjCNameWithTwoModules() {
@@ -112,6 +112,12 @@ public class FirLightTreeOldFrontendNativeDiagnosticsTestGenerated extends Abstr
runTest("compiler/testData/diagnostics/nativeTests/objCName5.kt");
}
@Test
@TestMetadata("objCNameWIthDifferentSwiftName.kt")
public void testObjCNameWIthDifferentSwiftName() {
runTest("compiler/testData/diagnostics/nativeTests/objCNameWIthDifferentSwiftName.kt");
}
@Test
@TestMetadata("objCNameWithTwoModules.kt")
public void testObjCNameWithTwoModules() {
@@ -112,6 +112,12 @@ public class FirPsiOldFrontendNativeDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/nativeTests/objCName5.kt");
}
@Test
@TestMetadata("objCNameWIthDifferentSwiftName.kt")
public void testObjCNameWIthDifferentSwiftName() {
runTest("compiler/testData/diagnostics/nativeTests/objCNameWIthDifferentSwiftName.kt");
}
@Test
@TestMetadata("objCNameWithTwoModules.kt")
public void testObjCNameWithTwoModules() {