diff --git a/compiler/fir/analysis-tests/testData/resolve/arguments/namedArrayInAnnotation.kt b/compiler/fir/analysis-tests/testData/resolve/arguments/namedArrayInAnnotation.kt new file mode 100644 index 00000000000..6fe69915cad --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/arguments/namedArrayInAnnotation.kt @@ -0,0 +1,4 @@ +annotation class Ann(vararg val strings: String) + +@Ann(strings = ["hello"]) +class A diff --git a/compiler/fir/analysis-tests/testData/resolve/arguments/namedArrayInAnnotation.txt b/compiler/fir/analysis-tests/testData/resolve/arguments/namedArrayInAnnotation.txt new file mode 100644 index 00000000000..a77e91a1646 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/arguments/namedArrayInAnnotation.txt @@ -0,0 +1,16 @@ +FILE: namedArrayInAnnotation.kt + public final annotation class Ann : R|kotlin/Annotation| { + public constructor(vararg strings: R|kotlin/Array|): R|Ann| { + super() + } + + public final val strings: R|kotlin/Array| = R|/strings| + public get(): R|kotlin/Array| + + } + @R|Ann|(vararg(strings = (String(hello)))) public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + } diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 3d3cc0025db..6b637485446 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -530,6 +530,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/analysis-tests/testData/resolve/arguments/lambdaInUnresolvedCall.kt"); } + @TestMetadata("namedArrayInAnnotation.kt") + public void testNamedArrayInAnnotation() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/arguments/namedArrayInAnnotation.kt"); + } + @TestMetadata("operatorsOverLiterals.kt") public void testOperatorsOverLiterals() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/arguments/operatorsOverLiterals.kt"); diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index 6d0ca273b29..56866a6e745 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -530,6 +530,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/arguments/lambdaInUnresolvedCall.kt"); } + @TestMetadata("namedArrayInAnnotation.kt") + public void testNamedArrayInAnnotation() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/arguments/namedArrayInAnnotation.kt"); + } + @TestMetadata("operatorsOverLiterals.kt") public void testOperatorsOverLiterals() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/arguments/operatorsOverLiterals.kt"); diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt index 3c8145fc6be..2f5568d319e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.resolve.calls.FirErrorReferenceWithCandidate import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate import org.jetbrains.kotlin.fir.resolve.calls.varargElementType import org.jetbrains.kotlin.fir.resolve.constructFunctionalTypeRef +import org.jetbrains.kotlin.fir.resolve.inference.inferenceComponents import org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType import org.jetbrains.kotlin.fir.resolve.inference.returnType @@ -34,6 +35,7 @@ import org.jetbrains.kotlin.fir.types.builder.buildStarProjection import org.jetbrains.kotlin.fir.types.builder.buildTypeProjectionWithVariance import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl import org.jetbrains.kotlin.fir.visitors.* +import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator import org.jetbrains.kotlin.types.AbstractTypeApproximator import org.jetbrains.kotlin.types.TypeApproximatorConfiguration import org.jetbrains.kotlin.types.Variance @@ -537,6 +539,17 @@ class FirCallCompletionResultsWriterTransformer( return constExpression.transform(integerApproximator, expectedType) } + override fun transformArrayOfCall(arrayOfCall: FirArrayOfCall, data: ExpectedArgumentType?): CompositeTransformResult { + if (arrayOfCall.typeRef !is FirImplicitTypeRef) return arrayOfCall.compose() + val expectedArrayType = data?.getExpectedType(arrayOfCall) + val expectedArrayElementType = expectedArrayType?.arrayElementType() + arrayOfCall.transformChildren(this, expectedArrayElementType?.toExpectedType()) + val arrayElementType = session.inferenceComponents.ctx.commonSuperTypeOrNull(arrayOfCall.arguments.map { it.typeRef.coneType }) + ?: session.builtinTypes.nullableAnyType.type + arrayOfCall.resultType = arrayOfCall.typeRef.resolvedTypeFromPrototype(arrayElementType.createArrayOf()) + return arrayOfCall.compose() + } + private fun FirNamedReferenceWithCandidate.toResolvedReference() = if (this is FirErrorReferenceWithCandidate) { buildErrorNamedReference { source = this@toResolvedReference.source