Skip to content

Commit d2d90d2

Browse files
KvanTTTSpace Team
authored andcommitted
[FIR] Report NO_CONSTRUCTOR instead of UNRESOLVED_REFERENCE
on calls to annotations without constructors KT-20677
1 parent fbda1e6 commit d2d90d2

8 files changed

+26
-24
lines changed

compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirCallResolver.kt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -639,17 +639,19 @@ class FirCallResolver(
639639

640640
val callInfo = toCallInfo(annotation, reference)
641641

642-
val resolutionResult = constructorSymbol
643-
?.let { runResolutionForGivenSymbol(callInfo, it) }
644-
?: ResolutionResult(callInfo, CandidateApplicability.HIDDEN, emptyList())
645-
createResolvedNamedReference(
646-
reference,
647-
reference.name,
648-
callInfo,
649-
resolutionResult.candidates,
650-
resolutionResult.applicability,
651-
explicitReceiver = null
652-
)
642+
if (constructorSymbol != null) {
643+
val resolutionResult = runResolutionForGivenSymbol(callInfo, constructorSymbol)
644+
createResolvedNamedReference(
645+
reference,
646+
reference.name,
647+
callInfo,
648+
resolutionResult.candidates,
649+
resolutionResult.applicability,
650+
explicitReceiver = null
651+
)
652+
} else {
653+
buildReferenceWithErrorCandidate(callInfo, ConeNoConstructorError, reference.source)
654+
}
653655
} else {
654656
annotation.replaceArgumentList(annotation.argumentList.transform(transformer, ResolutionMode.ContextDependent))
655657

compiler/testData/diagnostics/nativeTests/multiplatform/overrideInit_expectAnnotation.fir.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// LANGUAGE: +MultiPlatformProjects
2-
// DIAGNOSTICS: -UNUSED_PARAMETER -UNRESOLVED_REFERENCE
2+
// DIAGNOSTICS: -UNUSED_PARAMETER
33
// WITH_STDLIB
44
// WITH_PLATFORM_LIBS
55

@@ -16,13 +16,13 @@ expect annotation class MyOverrideInit
1616

1717
class DoesNotOverride : NSAssertionHandler {
1818
<!CONSTRUCTOR_DOES_NOT_OVERRIDE_ANY_SUPER_CONSTRUCTOR!>@OptIn(kotlinx.cinterop.BetaInteropApi::class)
19-
@MyOverrideInit
19+
@<!NO_CONSTRUCTOR!>MyOverrideInit<!>
2020
constructor(x: Int) { }<!>
2121
}
2222

2323
class OverridesOverriden : NSString {
2424
<!CONSTRUCTOR_OVERRIDES_ALREADY_OVERRIDDEN_OBJC_INITIALIZER!>@OptIn(kotlinx.cinterop.BetaInteropApi::class)
25-
@MyOverrideInit
25+
@<!NO_CONSTRUCTOR!>MyOverrideInit<!>
2626
constructor(coder: NSCoder) { }<!>
2727

2828
@Suppress("OVERRIDE_DEPRECATION")

compiler/testData/diagnostics/nativeTests/multiplatform/overrideInit_expectAnnotation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// LANGUAGE: +MultiPlatformProjects
2-
// DIAGNOSTICS: -UNUSED_PARAMETER -UNRESOLVED_REFERENCE
2+
// DIAGNOSTICS: -UNUSED_PARAMETER
33
// WITH_STDLIB
44
// WITH_PLATFORM_LIBS
55

compiler/testData/diagnostics/nativeTests/multiplatform/overrideInit_expectAnnotation.ll.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Checkers are run with Common session in Analysis API, so they can't see actualized declarations
33
// LL_FIR_DIVERGENCE
44
// LANGUAGE: +MultiPlatformProjects
5-
// DIAGNOSTICS: -UNUSED_PARAMETER -UNRESOLVED_REFERENCE
5+
// DIAGNOSTICS: -UNUSED_PARAMETER
66
// WITH_STDLIB
77
// WITH_PLATFORM_LIBS
88

@@ -19,13 +19,13 @@ expect annotation class MyOverrideInit
1919

2020
class DoesNotOverride : NSAssertionHandler {
2121
@OptIn(kotlinx.cinterop.BetaInteropApi::class)
22-
@MyOverrideInit
22+
@<!NO_CONSTRUCTOR!>MyOverrideInit<!>
2323
constructor(x: Int) { }
2424
}
2525

2626
class OverridesOverriden : NSString {
2727
@OptIn(kotlinx.cinterop.BetaInteropApi::class)
28-
@MyOverrideInit
28+
@<!NO_CONSTRUCTOR!>MyOverrideInit<!>
2929
constructor(coder: NSCoder) { }
3030

3131
@Suppress("OVERRIDE_DEPRECATION")

compiler/testData/diagnostics/tests/multiplatform/errorWhenUseExpectAnnWithoutDefaultConstructor.fir.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
<!NO_ACTUAL_FOR_EXPECT{JVM}!>expect<!> annotation class Ann
77

8-
@<!UNRESOLVED_REFERENCE!>Ann<!>
8+
<!NO_CONSTRUCTOR!>@Ann<!>
99
fun commonFoo() {}
1010

1111
// MODULE: m1-jvm()()(m1-common)
1212

13-
@<!UNRESOLVED_REFERENCE!>Ann<!>
13+
<!NO_CONSTRUCTOR!>@Ann<!>
1414
fun platformFoo() {}
1515

1616
/* GENERATED_FIR_TAGS: annotationDeclaration, expect, functionDeclaration */

compiler/testData/diagnostics/tests/multiplatform/errorWhenUseExpectAnnWithoutDefaultConstructor.ll.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
expect annotation class Ann
77

8-
@<!UNRESOLVED_REFERENCE!>Ann<!>
8+
<!NO_CONSTRUCTOR!>@Ann<!>
99
fun commonFoo() {}
1010

1111
// MODULE: m1-jvm()()(m1-common)
1212

13-
@<!UNRESOLVED_REFERENCE!>Ann<!>
13+
<!NO_CONSTRUCTOR!>@Ann<!>
1414
fun platformFoo() {}
1515

1616
/* GENERATED_FIR_TAGS: annotationDeclaration, expect, functionDeclaration */

compiler/testData/diagnostics/tests/multiplatform/headerClass/actualClassWithDefaultValuesInAnnotationViaTypealias.fir.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ expect annotation class Foo5()
1111
expect annotation class Foo6()
1212
<!EXPECT_ACTUAL_IR_INCOMPATIBILITY{JVM}!>expect<!> annotation class Foo7<!EXPECT_ACTUAL_IR_MISMATCH{JVM}!>()<!>
1313

14-
@<!UNRESOLVED_REFERENCE!>Foo1<!>
14+
<!NO_CONSTRUCTOR!>@Foo1<!>
1515
fun foo() {}
1616

1717
@Foo5

compiler/testData/diagnostics/tests/multiplatform/headerClass/actualClassWithDefaultValuesInAnnotationViaTypealias.ll.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ expect annotation class Foo5()
1111
expect annotation class Foo6()
1212
expect annotation class Foo7()
1313

14-
@<!UNRESOLVED_REFERENCE!>Foo1<!>
14+
<!NO_CONSTRUCTOR!>@Foo1<!>
1515
fun foo() {}
1616

1717
@Foo5

0 commit comments

Comments
 (0)