From 68259f7939acbd63a75e235870cbc226894f0fc8 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Wed, 13 Sep 2017 16:05:46 +0300 Subject: [PATCH] Allow assigning array to vararg in named form in annotations See more in KT-20171 --- .../jetbrains/kotlin/diagnostics/Errors.java | 2 + .../kotlin/diagnostics/diagnosticUtils.kt | 2 +- .../rendering/DefaultErrorMessages.java | 1 + .../kotlin/resolve/calls/CallCompleter.kt | 2 +- .../kotlin/resolve/calls/CallResolverUtil.kt | 39 ++++++++++- .../kotlin/resolve/calls/CandidateResolver.kt | 2 +- .../resolve/calls/GenericCandidateResolver.kt | 6 +- .../calls/inference/CoroutineInferenceUtil.kt | 4 +- .../tower/KotlinToResolvedCallTransformer.kt | 2 +- .../evaluate/ConstantExpressionEvaluator.kt | 8 +++ .../assigningArrayToVarargInAnnotation.kt | 68 +++++++++++++++++++ .../assigningArraysToVarargsInAnnotations.kt | 45 ++++++++++++ .../assigningArraysToVarargsInAnnotations.txt | 37 ++++++++++ .../noAssigningArraysToVarargsFeature.kt | 48 +++++++++++++ .../noAssigningArraysToVarargsFeature.txt | 38 +++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 6 ++ .../CompilerLightClassTestGenerated.java | 47 ++++++------- .../checkers/DiagnosticsTestGenerated.java | 24 +++++++ .../DiagnosticsUsingJavacTestGenerated.java | 24 +++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++ .../LightAnalysisModeTestGenerated.java | 6 ++ .../kotlin/config/LanguageVersionSettings.kt | 1 + .../kotlin/builtins/KotlinBuiltIns.java | 6 +- .../IdeCompiledLightClassTestGenerated.java | 33 ++------- .../resolve/IdeLightClassTestGenerated.java | 37 +++------- .../semantics/JsCodegenBoxTestGenerated.java | 12 ++++ 26 files changed, 410 insertions(+), 96 deletions(-) create mode 100644 compiler/testData/codegen/box/vararg/assigningArrayToVarargInAnnotation.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/assigningArraysToVarargsInAnnotations.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/assigningArraysToVarargsInAnnotations.txt create mode 100644 compiler/testData/diagnostics/tests/varargs/noAssigningArraysToVarargsFeature.kt create mode 100644 compiler/testData/diagnostics/tests/varargs/noAssigningArraysToVarargsFeature.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 1155effef6a..71ceb80266f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -620,6 +620,8 @@ public interface Errors { DiagnosticFactory1 MISSING_RECEIVER = DiagnosticFactory1.create(ERROR); DiagnosticFactory0 NO_RECEIVER_ALLOWED = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 ASSIGNING_SINGLE_ELEMENT_TO_VARARG_IN_NAMED_FORM = DiagnosticFactory0.create(WARNING); + // Call resolution DiagnosticFactory0 ILLEGAL_SELECTOR = DiagnosticFactory0.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/diagnosticUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/diagnosticUtils.kt index 2a700ce17e2..11105950639 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/diagnosticUtils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/diagnosticUtils.kt @@ -55,7 +55,7 @@ fun ResolutionContext<*>.reportTypeMismatchDueToTypeProjection( is CallPosition.ValueArgumentPosition -> Pair( callPosition.resolvedCall, { f: CallableDescriptor -> - getEffectiveExpectedType(f.valueParameters[callPosition.valueParameter.index], callPosition.valueArgument) + getEffectiveExpectedType(f.valueParameters[callPosition.valueParameter.index], callPosition.valueArgument, this) }) is CallPosition.ExtensionReceiverPosition -> Pair( callPosition.resolvedCall, { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 4a75e0e2642..1015305dac2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -756,6 +756,7 @@ public class DefaultErrorMessages { MAP.put(NO_VALUE_FOR_PARAMETER, "No value passed for parameter ''{0}''", NAME); MAP.put(MISSING_RECEIVER, "A receiver of type {0} is required", RENDER_TYPE); MAP.put(NO_RECEIVER_ALLOWED, "No receiver can be passed to this function or property"); + MAP.put(ASSIGNING_SINGLE_ELEMENT_TO_VARARG_IN_NAMED_FORM, "Assigning single elements to varargs in named form is deprecated"); MAP.put(CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS, "Cannot create an instance of an abstract class"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt index bca8fd9d655..2b572882cb1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt @@ -278,7 +278,7 @@ class CallCompleter( val argumentMapping = getArgumentMapping(valueArgument!!) val (expectedType, callPosition) = when (argumentMapping) { is ArgumentMatch -> Pair( - getEffectiveExpectedType(argumentMapping.valueParameter, valueArgument), + getEffectiveExpectedType(argumentMapping.valueParameter, valueArgument, context), CallPosition.ValueArgumentPosition(results.resultingCall, argumentMapping.valueParameter, valueArgument)) else -> Pair(TypeUtils.NO_EXPECTED_TYPE, CallPosition.Unknown) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolverUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolverUtil.kt index 4750766db5b..0a4353077b5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolverUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolverUtil.kt @@ -18,16 +18,21 @@ package org.jetbrains.kotlin.resolve.calls.callResolverUtil import com.google.common.collect.Lists import com.intellij.util.containers.ContainerUtil +import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.ReflectionTypes import org.jetbrains.kotlin.builtins.isSuspendFunctionType +import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor import org.jetbrains.kotlin.lexer.KtToken import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.CallTransformer import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.calls.callUtil.getValueArgumentForExpression +import org.jetbrains.kotlin.resolve.calls.components.isVararg +import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystem import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.EXPECTED_TYPE_POSITION import org.jetbrains.kotlin.resolve.calls.inference.getNestedTypeVariables @@ -45,6 +50,7 @@ import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import org.jetbrains.kotlin.types.expressions.OperatorConventions import org.jetbrains.kotlin.types.typeUtil.contains +import org.jetbrains.kotlin.utils.addToStdlib.safeAs enum class ResolveArgumentsMode { RESOLVE_FUNCTION_ARGUMENTS, @@ -177,8 +183,12 @@ fun getSuperCallExpression(call: Call): KtSuperExpression? { return (call.explicitReceiver as? ExpressionReceiver)?.expression as? KtSuperExpression } -fun getEffectiveExpectedType(parameterDescriptor: ValueParameterDescriptor, argument: ValueArgument): KotlinType { - if (argument.getSpreadElement() != null) { +fun getEffectiveExpectedType( + parameterDescriptor: ValueParameterDescriptor, + argument: ValueArgument, + context: ResolutionContext<*> +): KotlinType { + if (argument.getSpreadElement() != null || shouldCheckAsArray(parameterDescriptor, argument, context)) { if (parameterDescriptor.varargElementType == null) { // Spread argument passed to a non-vararg parameter, an error is already reported by ValueArgumentsToParametersMapper return DONT_CARE @@ -193,6 +203,31 @@ fun getEffectiveExpectedType(parameterDescriptor: ValueParameterDescriptor, argu return parameterDescriptor.type } +private fun shouldCheckAsArray( + parameterDescriptor: ValueParameterDescriptor, + argument: ValueArgument, + context: ResolutionContext<*> +): Boolean { + if (!context.languageVersionSettings.supportsFeature(LanguageFeature.AssigningArraysToVarargsInNamedFormInAnnotations)) return false + + if (!isParameterOfAnnotation(parameterDescriptor)) return false + + return argument.isNamed() && parameterDescriptor.isVararg && isArrayOrArrayLiteral(argument, context) +} + +fun isParameterOfAnnotation(parameterDescriptor: ValueParameterDescriptor): Boolean { + val constructedClass = parameterDescriptor.containingDeclaration.safeAs()?.constructedClass + return DescriptorUtils.isAnnotationClass(constructedClass) +} + +fun isArrayOrArrayLiteral(argument: ValueArgument, context: ResolutionContext<*>): Boolean { + val argumentExpression = argument.getArgumentExpression() ?: return false + if (argumentExpression is KtCollectionLiteralExpression) return true + + val type = context.trace.getType(argumentExpression) ?: return false + return KotlinBuiltIns.isArrayOrPrimitiveArray(type) +} + fun createResolutionCandidatesForConstructors( lexicalScope: LexicalScope, call: Call, diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt index d380e249bd4..ee98596a225 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt @@ -363,7 +363,7 @@ class CandidateResolver( for (argument in resolvedArgument.arguments) { val expression = argument.getArgumentExpression() ?: continue - val expectedType = getEffectiveExpectedType(parameterDescriptor, argument) + val expectedType = getEffectiveExpectedType(parameterDescriptor, argument, context) val newContext = context.replaceDataFlowInfo(infoForArguments.getInfo(argument)).replaceExpectedType(expectedType) val typeInfoForCall = argumentTypeResolver.getArgumentTypeInfo(expression, newContext, resolveFunctionArgumentBodies) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt index c4597836c1a..de0a0041b0e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt @@ -174,7 +174,7 @@ class GenericCandidateResolver( context: CallCandidateResolutionContext<*>, resolveFunctionArgumentBodies: ResolveArgumentsMode ) { - val effectiveExpectedType = getEffectiveExpectedType(valueParameterDescriptor, valueArgument) + val effectiveExpectedType = getEffectiveExpectedType(valueParameterDescriptor, valueArgument, context) val argumentExpression = valueArgument.getArgumentExpression() val expectedType = substitutor.substitute(effectiveExpectedType, Variance.INVARIANT) @@ -336,7 +336,7 @@ class GenericCandidateResolver( ) { val argumentExpression = valueArgument.getArgumentExpression() ?: return - val effectiveExpectedType = getEffectiveExpectedType(valueParameterDescriptor, valueArgument) + val effectiveExpectedType = getEffectiveExpectedType(valueParameterDescriptor, valueArgument, context) if (isCoroutineCallWithAdditionalInference(valueParameterDescriptor, valueArgument)) { coroutineInferenceSupport.analyzeCoroutine(functionLiteral, valueArgument, constraintSystem, context, effectiveExpectedType) @@ -398,7 +398,7 @@ class GenericCandidateResolver( constraintSystem: ConstraintSystem.Builder, context: CallCandidateResolutionContext ) { - val effectiveExpectedType = getEffectiveExpectedType(valueParameterDescriptor, valueArgument) + val effectiveExpectedType = getEffectiveExpectedType(valueParameterDescriptor, valueArgument, context) val expectedType = getExpectedTypeForCallableReference(callableReference, constraintSystem, context, effectiveExpectedType) ?: return if (!ReflectionTypes.isCallableType(expectedType)) return diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceUtil.kt index bd2e8700420..a9f3da8e0ab 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceUtil.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -203,7 +203,7 @@ class CoroutineInferenceSupport( ?: return@forceInferenceForArguments with(NewKotlinTypeChecker) { - val parameterType = getEffectiveExpectedType(argumentMatch.valueParameter, valueArgument) + val parameterType = getEffectiveExpectedType(argumentMatch.valueParameter, valueArgument, context) CoroutineTypeCheckerContext().isSubtypeOf(kotlinType.unwrap(), parameterType.unwrap()) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt index 3f4102ac76f..3835ae68f04 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt @@ -176,7 +176,7 @@ class KotlinToResolvedCallTransformer( val argumentMapping = resolvedCall.getArgumentMapping(valueArgument!!) val (expectedType, callPosition) = when (argumentMapping) { is ArgumentMatch -> Pair( - getEffectiveExpectedType(argumentMapping.valueParameter, valueArgument), + getEffectiveExpectedType(argumentMapping.valueParameter, valueArgument, context), CallPosition.ValueArgumentPosition(resolvedCall, argumentMapping.valueParameter, valueArgument)) else -> Pair(TypeUtils.NO_EXPECTED_TYPE, CallPosition.Unknown) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt index 7fbe2aa6e9b..4fb38f5a799 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt @@ -101,6 +101,8 @@ class ConstantExpressionEvaluator( val constants = compileTimeConstants.map { it.toConstantValue(constantType) } if (argumentsAsVararg) { + if (isArrayPassedInNamedForm(constants, resolvedArgument)) return constants.single() + if (parameterDescriptor.declaresDefaultValue() && compileTimeConstants.isEmpty()) return null return constantValueFactory.createArrayValue(constants, parameterDescriptor.type) @@ -111,6 +113,12 @@ class ConstantExpressionEvaluator( } } + private fun isArrayPassedInNamedForm(constants: List>, resolvedArgument: ResolvedValueArgument): Boolean { + val constant = constants.singleOrNull() ?: return false + val argument = resolvedArgument.arguments.singleOrNull() ?: return false + return KotlinBuiltIns.isArrayOrPrimitiveArray(constant.type) && argument.isNamed() + } + private fun checkCompileTimeConstant( argumentExpression: KtExpression, expectedType: KotlinType, diff --git a/compiler/testData/codegen/box/vararg/assigningArrayToVarargInAnnotation.kt b/compiler/testData/codegen/box/vararg/assigningArrayToVarargInAnnotation.kt new file mode 100644 index 00000000000..354ab6bddbf --- /dev/null +++ b/compiler/testData/codegen/box/vararg/assigningArrayToVarargInAnnotation.kt @@ -0,0 +1,68 @@ +// LANGUAGE_VERSION: 1.2 +// WITH_REFLECT + +// IGNORE_BACKEND: JS +// IGNORE_BACKEND: NATIVE + +// FILE: JavaAnn.java + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +@interface JavaAnn { + String[] value() default {}; + String[] path() default {}; +} + +// FILE: test.kt + +import java.util.Arrays +import kotlin.reflect.KClass +import kotlin.reflect.KFunction0 +import kotlin.reflect.full.findAnnotation + +inline fun test(kFunction: KFunction0, test: T.() -> Unit) { + val annotation = kFunction.findAnnotation()!! + annotation.test() +} + +fun check(b: Boolean, message: String) { + if (!b) throw RuntimeException(message) +} + +annotation class Ann(vararg val s: String) + +@Ann(s = ["value1", "value2"]) +fun test1() {} + +@Ann(s = arrayOf("value3", "value4")) +fun test2() {} + +@JavaAnn(value = ["value5"], path = ["value6"]) +fun test3() {} + +@JavaAnn("value7", path = ["value8"]) +fun test4() {} + +fun box(): String { + test(::test1) { + check(s.contentEquals(arrayOf("value1", "value2")), "Fail 1: ${s.joinToString()}") + } + + test(::test2) { + check(s.contentEquals(arrayOf("value3", "value4")), "Fail 2: ${s.joinToString()}") + } + + test(::test3) { + check(value.contentEquals(arrayOf("value5")), "Fail 3: ${value.joinToString()}") + check(path.contentEquals(arrayOf("value6")), "Fail 3: ${path.joinToString()}") + } + + test(::test4) { + check(value.contentEquals(arrayOf("value7")), "Fail 4: ${value.joinToString()}") + check(path.contentEquals(arrayOf("value8")), "Fail 4: ${path.joinToString()}") + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/assigningArraysToVarargsInAnnotations.kt b/compiler/testData/diagnostics/tests/varargs/assigningArraysToVarargsInAnnotations.kt new file mode 100644 index 00000000000..f60f61bbc20 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/assigningArraysToVarargsInAnnotations.kt @@ -0,0 +1,45 @@ +// !LANGUAGE: +ArrayLiteralsInAnnotations, +AssigningArraysToVarargsInNamedFormInAnnotations + +// FILE: JavaAnn.java + +@interface JavaAnn { + String[] value() default {}; + String[] path() default {}; +} + +// FILE: test.kt + +annotation class Ann(vararg val s: String) + +@Ann(s = arrayOf()) +fun test1() {} + +@Ann(s = intArrayOf()) +fun test2() {} + +@Ann(s = arrayOf(1)) +fun test3() {} + +@Ann("value1", "value2") +fun test4() {} + +@Ann(s = ["value"]) +fun test5() {} + +@JavaAnn(value = arrayOf("value")) +fun jTest1() {} + +@JavaAnn(value = ["value"]) +fun jTest2() {} + +@JavaAnn(value = ["value"], path = ["path"]) +fun jTest3() {} + + +annotation class IntAnn(vararg val i: Int) + +@IntAnn(i = [1, 2]) +fun foo1() {} + +@IntAnn(i = intArrayOf(0)) +fun foo2() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/assigningArraysToVarargsInAnnotations.txt b/compiler/testData/diagnostics/tests/varargs/assigningArraysToVarargsInAnnotations.txt new file mode 100644 index 00000000000..99fc22be605 --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/assigningArraysToVarargsInAnnotations.txt @@ -0,0 +1,37 @@ +package + +@IntAnn(i = {1, 2}) public fun foo1(): kotlin.Unit +@IntAnn(i = {0}) public fun foo2(): kotlin.Unit +@JavaAnn(value = {"value"}) public fun jTest1(): kotlin.Unit +@JavaAnn(value = {"value"}) public fun jTest2(): kotlin.Unit +@JavaAnn(path = {"path"}, value = {"value"}) public fun jTest3(): kotlin.Unit +@Ann(s = {}) public fun test1(): kotlin.Unit +@Ann(s = {}) public fun test2(): kotlin.Unit +@Ann(s = {1}) public fun test3(): kotlin.Unit +@Ann(s = {"value1", "value2"}) public fun test4(): kotlin.Unit +@Ann(s = {"value"}) public fun test5(): kotlin.Unit + +public final annotation class Ann : kotlin.Annotation { + public constructor Ann(/*0*/ vararg s: kotlin.String /*kotlin.Array*/) + public final val s: kotlin.Array + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final annotation class IntAnn : kotlin.Annotation { + public constructor IntAnn(/*0*/ vararg i: kotlin.Int /*kotlin.IntArray*/) + public final val i: kotlin.IntArray + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public/*package*/ final annotation class JavaAnn : kotlin.Annotation { + public/*package*/ constructor JavaAnn(/*0*/ vararg value: kotlin.String /*kotlin.Array*/ = ..., /*1*/ path: kotlin.Array = ...) + public final val path: kotlin.Array + public final val value: kotlin.Array + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/varargs/noAssigningArraysToVarargsFeature.kt b/compiler/testData/diagnostics/tests/varargs/noAssigningArraysToVarargsFeature.kt new file mode 100644 index 00000000000..1872f59396d --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/noAssigningArraysToVarargsFeature.kt @@ -0,0 +1,48 @@ +// !LANGUAGE: +ArrayLiteralsInAnnotations, -AssigningArraysToVarargsInNamedFormInAnnotations + +// FILE: JavaAnn.java + +@interface JavaAnn { + String[] value() default {}; + String[] path() default {}; +} + +// FILE: test.kt + +annotation class Ann(vararg val s: String) + +@Ann(s = arrayOf()) +fun test1() {} + +@Ann(s = intArrayOf()) +fun test2() {} + +@Ann(s = arrayOf(1)) +fun test3() {} + +@Ann(s = ["value"]) +fun test5() {} + +@JavaAnn(value = arrayOf("value")) +fun jTest1() {} + +@JavaAnn(value = ["value"]) +fun jTest2() {} + +@JavaAnn(value = ["value"], path = ["path"]) +fun jTest3() {} + +annotation class IntAnn(vararg val i: Int) + +@IntAnn(i = [1, 2]) +fun foo1() {} + +@IntAnn(i = intArrayOf(0)) +fun foo2() {} + +fun foo(vararg i: Int) {} + +@Ann(s = "value") +fun dep1() { + foo(i = 1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/noAssigningArraysToVarargsFeature.txt b/compiler/testData/diagnostics/tests/varargs/noAssigningArraysToVarargsFeature.txt new file mode 100644 index 00000000000..2f22dcdcc7a --- /dev/null +++ b/compiler/testData/diagnostics/tests/varargs/noAssigningArraysToVarargsFeature.txt @@ -0,0 +1,38 @@ +package + +@Ann(s = {"value"}) public fun dep1(): kotlin.Unit +public fun foo(/*0*/ vararg i: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit +@IntAnn(i = {1, 2}) public fun foo1(): kotlin.Unit +@IntAnn(i = {0}) public fun foo2(): kotlin.Unit +@JavaAnn(value = {"value"}) public fun jTest1(): kotlin.Unit +@JavaAnn(value = {"value"}) public fun jTest2(): kotlin.Unit +@JavaAnn(path = {"path"}, value = {"value"}) public fun jTest3(): kotlin.Unit +@Ann(s = {}) public fun test1(): kotlin.Unit +@Ann(s = {}) public fun test2(): kotlin.Unit +@Ann(s = {1}) public fun test3(): kotlin.Unit +@Ann(s = {"value"}) public fun test5(): kotlin.Unit + +public final annotation class Ann : kotlin.Annotation { + public constructor Ann(/*0*/ vararg s: kotlin.String /*kotlin.Array*/) + public final val s: kotlin.Array + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final annotation class IntAnn : kotlin.Annotation { + public constructor IntAnn(/*0*/ vararg i: kotlin.Int /*kotlin.IntArray*/) + public final val i: kotlin.IntArray + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public/*package*/ final annotation class JavaAnn : kotlin.Annotation { + public/*package*/ constructor JavaAnn(/*0*/ vararg value: kotlin.String /*kotlin.Array*/ = ..., /*1*/ path: kotlin.Array = ...) + public final val path: kotlin.Array + public final val value: kotlin.Array + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 46b3138f625..bb61108aac8 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -19631,6 +19631,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/vararg"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("assigningArrayToVarargInAnnotation.kt") + public void testAssigningArrayToVarargInAnnotation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/vararg/assigningArrayToVarargInAnnotation.kt"); + doTest(fileName); + } + @TestMetadata("kt1978.kt") public void testKt1978() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/vararg/kt1978.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/asJava/CompilerLightClassTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/asJava/CompilerLightClassTestGenerated.java index d6992108432..cab1938a04c 100644 --- a/compiler/tests/org/jetbrains/kotlin/asJava/CompilerLightClassTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/asJava/CompilerLightClassTestGenerated.java @@ -33,7 +33,7 @@ import java.util.regex.Pattern; @RunWith(JUnit3RunnerWithInners.class) public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassTest { public void testAllFilesPresentInLightClasses() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true, "local", "ideRegression"); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true, "local", "ideRegression"); } @TestMetadata("AnnotationClass.kt") @@ -161,7 +161,7 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT @RunWith(JUnit3RunnerWithInners.class) public static class CompilationErrors extends AbstractCompilerLightClassTest { public void testAllFilesPresentInCompilationErrors() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/compilationErrors"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/compilationErrors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("AnnotationModifiers.kt") @@ -212,7 +212,7 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT @RunWith(JUnit3RunnerWithInners.class) public static class Delegation extends AbstractCompilerLightClassTest { public void testAllFilesPresentInDelegation() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/delegation"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/delegation"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("Function.kt") @@ -226,6 +226,12 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/delegation/Property.kt"); doTest(fileName); } + + @TestMetadata("WithPlatformTypes.NoCompile.kt") + public void testWithPlatformTypes_NoCompile() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/delegation/WithPlatformTypes.NoCompile.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/asJava/lightClasses/facades") @@ -233,7 +239,13 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT @RunWith(JUnit3RunnerWithInners.class) public static class Facades extends AbstractCompilerLightClassTest { public void testAllFilesPresentInFacades() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/facades"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/facades"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("EmptyFile.NoCompile.kt") + public void testEmptyFile_NoCompile() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/facades/EmptyFile.NoCompile.kt"); + doTest(fileName); } @TestMetadata("MultiFile.kt") @@ -260,7 +272,7 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT @RunWith(JUnit3RunnerWithInners.class) public static class NullabilityAnnotations extends AbstractCompilerLightClassTest { public void testAllFilesPresentInNullabilityAnnotations() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/nullabilityAnnotations"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/nullabilityAnnotations"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("Class.kt") @@ -377,7 +389,7 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT @RunWith(JUnit3RunnerWithInners.class) public static class Object extends AbstractCompilerLightClassTest { public void testAllFilesPresentInObject() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/object"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/object"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("SimpleObject.kt") @@ -392,7 +404,7 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT @RunWith(JUnit3RunnerWithInners.class) public static class PublicField extends AbstractCompilerLightClassTest { public void testAllFilesPresentInPublicField() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/publicField"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/publicField"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("CompanionObject.kt") @@ -407,25 +419,4 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT doTest(fileName); } } - - @TestMetadata("compiler/testData/asJava/lightClasses/script") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Script extends AbstractCompilerLightClassTest { - public void testAllFilesPresentInScript() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/script"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); - } - - @TestMetadata("HelloWorld.kts") - public void testHelloWorld() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/script/HelloWorld.kts"); - doTest(fileName); - } - - @TestMetadata("InnerClasses.kts") - public void testInnerClasses() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/script/InnerClasses.kts"); - doTest(fileName); - } - } } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 09244818143..14446c3aa10 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -23776,6 +23776,24 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("assigningArraysToVarargsInAnnotations.kt") + public void testAssigningArraysToVarargsInAnnotations() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/assigningArraysToVarargsInAnnotations.kt"); + doTest(fileName); + } + + @TestMetadata("assigningSingleElementsInNamedFormAnnDeprecation.kt") + public void testAssigningSingleElementsInNamedFormAnnDeprecation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormAnnDeprecation.kt"); + doTest(fileName); + } + + @TestMetadata("assigningSingleElementsInNamedFormFunDeprecation.kt") + public void testAssigningSingleElementsInNamedFormFunDeprecation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormFunDeprecation.kt"); + doTest(fileName); + } + @TestMetadata("kt1781.kt") public void testKt1781() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/kt1781.kt"); @@ -23830,6 +23848,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("noAssigningArraysToVarargsFeature.kt") + public void testNoAssigningArraysToVarargsFeature() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/noAssigningArraysToVarargsFeature.kt"); + doTest(fileName); + } + @TestMetadata("NullableTypeForVarargArgument.kt") public void testNullableTypeForVarargArgument() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/NullableTypeForVarargArgument.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 95ec9329390..eb533b29407 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -23776,6 +23776,24 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing doTest(fileName); } + @TestMetadata("assigningArraysToVarargsInAnnotations.kt") + public void testAssigningArraysToVarargsInAnnotations() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/assigningArraysToVarargsInAnnotations.kt"); + doTest(fileName); + } + + @TestMetadata("assigningSingleElementsInNamedFormAnnDeprecation.kt") + public void testAssigningSingleElementsInNamedFormAnnDeprecation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormAnnDeprecation.kt"); + doTest(fileName); + } + + @TestMetadata("assigningSingleElementsInNamedFormFunDeprecation.kt") + public void testAssigningSingleElementsInNamedFormFunDeprecation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/assigningSingleElementsInNamedFormFunDeprecation.kt"); + doTest(fileName); + } + @TestMetadata("kt1781.kt") public void testKt1781() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/kt1781.kt"); @@ -23830,6 +23848,12 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing doTest(fileName); } + @TestMetadata("noAssigningArraysToVarargsFeature.kt") + public void testNoAssigningArraysToVarargsFeature() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/noAssigningArraysToVarargsFeature.kt"); + doTest(fileName); + } + @TestMetadata("NullableTypeForVarargArgument.kt") public void testNullableTypeForVarargArgument() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/NullableTypeForVarargArgument.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index c18b96c8887..5b0faa83bc2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -19631,6 +19631,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/vararg"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("assigningArrayToVarargInAnnotation.kt") + public void testAssigningArrayToVarargInAnnotation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/vararg/assigningArrayToVarargInAnnotation.kt"); + doTest(fileName); + } + @TestMetadata("kt1978.kt") public void testKt1978() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/vararg/kt1978.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index a76879bc4cd..dd3ec546002 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -19631,6 +19631,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/vararg"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("assigningArrayToVarargInAnnotation.kt") + public void testAssigningArrayToVarargInAnnotation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/vararg/assigningArrayToVarargInAnnotation.kt"); + doTest(fileName); + } + @TestMetadata("kt1978.kt") public void testKt1978() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/vararg/kt1978.kt"); diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index adb2b01ec90..b47eb17ac67 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -63,6 +63,7 @@ enum class LanguageFeature( CallableReferencesToClassMembersWithEmptyLHS(KOTLIN_1_2), ThrowNpeOnExplicitEqualsForBoxedNull(KOTLIN_1_2), JvmPackageName(KOTLIN_1_2), + AssigningArraysToVarargsInNamedFormInAnnotations(KOTLIN_1_2), RestrictionOfValReassignmentViaBackingField(KOTLIN_1_3), NestedClassesInEnumEntryShouldBeInner(KOTLIN_1_3), diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java index a5f414e7310..6e40c4674f3 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -866,6 +866,10 @@ public abstract class KotlinBuiltIns { return classFqNameEquals(descriptor, FQ_NAMES.array) || getPrimitiveArrayType(descriptor) != null; } + public static boolean isArrayOrPrimitiveArray(@NotNull KotlinType type) { + return isArray(type) || isPrimitiveArray(type); + } + public static boolean isPrimitiveArray(@NotNull KotlinType type) { ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor(); return descriptor != null && getPrimitiveArrayType(descriptor) != null; diff --git a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeCompiledLightClassTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeCompiledLightClassTestGenerated.java index fc0d2b63c2d..cadfcabdf8e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeCompiledLightClassTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeCompiledLightClassTestGenerated.java @@ -33,7 +33,7 @@ import java.util.regex.Pattern; @RunWith(JUnit3RunnerWithInners.class) public class IdeCompiledLightClassTestGenerated extends AbstractIdeCompiledLightClassTest { public void testAllFilesPresentInLightClasses() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true, "local", "compilationErrors", "ideRegression"); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true, "local", "compilationErrors", "ideRegression"); } @TestMetadata("AnnotationClass.kt") @@ -161,7 +161,7 @@ public class IdeCompiledLightClassTestGenerated extends AbstractIdeCompiledLight @RunWith(JUnit3RunnerWithInners.class) public static class Delegation extends AbstractIdeCompiledLightClassTest { public void testAllFilesPresentInDelegation() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/delegation"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/delegation"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("Function.kt") @@ -182,7 +182,7 @@ public class IdeCompiledLightClassTestGenerated extends AbstractIdeCompiledLight @RunWith(JUnit3RunnerWithInners.class) public static class Facades extends AbstractIdeCompiledLightClassTest { public void testAllFilesPresentInFacades() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/facades"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/facades"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("MultiFile.kt") @@ -209,7 +209,7 @@ public class IdeCompiledLightClassTestGenerated extends AbstractIdeCompiledLight @RunWith(JUnit3RunnerWithInners.class) public static class NullabilityAnnotations extends AbstractIdeCompiledLightClassTest { public void testAllFilesPresentInNullabilityAnnotations() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/nullabilityAnnotations"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/nullabilityAnnotations"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("Class.kt") @@ -326,7 +326,7 @@ public class IdeCompiledLightClassTestGenerated extends AbstractIdeCompiledLight @RunWith(JUnit3RunnerWithInners.class) public static class Object extends AbstractIdeCompiledLightClassTest { public void testAllFilesPresentInObject() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/object"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/object"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("SimpleObject.kt") @@ -341,7 +341,7 @@ public class IdeCompiledLightClassTestGenerated extends AbstractIdeCompiledLight @RunWith(JUnit3RunnerWithInners.class) public static class PublicField extends AbstractIdeCompiledLightClassTest { public void testAllFilesPresentInPublicField() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/publicField"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/publicField"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("CompanionObject.kt") @@ -356,25 +356,4 @@ public class IdeCompiledLightClassTestGenerated extends AbstractIdeCompiledLight doTest(fileName); } } - - @TestMetadata("compiler/testData/asJava/lightClasses/script") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Script extends AbstractIdeCompiledLightClassTest { - public void testAllFilesPresentInScript() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/script"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); - } - - @TestMetadata("HelloWorld.kts") - public void testHelloWorld() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/script/HelloWorld.kts"); - doTest(fileName); - } - - @TestMetadata("InnerClasses.kts") - public void testInnerClasses() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/script/InnerClasses.kts"); - doTest(fileName); - } - } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeLightClassTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeLightClassTestGenerated.java index f3ccf19ce7f..75c845fefdc 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeLightClassTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeLightClassTestGenerated.java @@ -33,7 +33,7 @@ import java.util.regex.Pattern; @RunWith(JUnit3RunnerWithInners.class) public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest { public void testAllFilesPresentInLightClasses() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true, "delegation"); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true, "delegation"); } @TestMetadata("AnnotationClass.kt") @@ -161,7 +161,7 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest { @RunWith(JUnit3RunnerWithInners.class) public static class CompilationErrors extends AbstractIdeLightClassTest { public void testAllFilesPresentInCompilationErrors() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/compilationErrors"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/compilationErrors"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("AnnotationModifiers.kt") @@ -212,7 +212,7 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest { @RunWith(JUnit3RunnerWithInners.class) public static class Facades extends AbstractIdeLightClassTest { public void testAllFilesPresentInFacades() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/facades"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/facades"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("MultiFile.kt") @@ -239,7 +239,7 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest { @RunWith(JUnit3RunnerWithInners.class) public static class IdeRegression extends AbstractIdeLightClassTest { public void testAllFilesPresentInIdeRegression() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/ideRegression"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/ideRegression"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("AllOpenAnnotatedClasses.kt") @@ -296,7 +296,7 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest { @RunWith(JUnit3RunnerWithInners.class) public static class Local extends AbstractIdeLightClassTest { public void testAllFilesPresentInLocal() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/local"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/local"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("DollarsInNameLocal.kt") @@ -311,7 +311,7 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest { @RunWith(JUnit3RunnerWithInners.class) public static class NullabilityAnnotations extends AbstractIdeLightClassTest { public void testAllFilesPresentInNullabilityAnnotations() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/nullabilityAnnotations"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/nullabilityAnnotations"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("Class.kt") @@ -428,7 +428,7 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest { @RunWith(JUnit3RunnerWithInners.class) public static class Object extends AbstractIdeLightClassTest { public void testAllFilesPresentInObject() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/object"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/object"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("SimpleObject.kt") @@ -443,7 +443,7 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest { @RunWith(JUnit3RunnerWithInners.class) public static class PublicField extends AbstractIdeLightClassTest { public void testAllFilesPresentInPublicField() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/publicField"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/publicField"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true); } @TestMetadata("CompanionObject.kt") @@ -458,25 +458,4 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest { doTest(fileName); } } - - @TestMetadata("compiler/testData/asJava/lightClasses/script") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Script extends AbstractIdeLightClassTest { - public void testAllFilesPresentInScript() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/script"), Pattern.compile("^([^.]+)\\.(kt|kts)$"), TargetBackend.ANY, true); - } - - @TestMetadata("HelloWorld.kts") - public void testHelloWorld() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/script/HelloWorld.kts"); - doTest(fileName); - } - - @TestMetadata("InnerClasses.kts") - public void testInnerClasses() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/script/InnerClasses.kts"); - doTest(fileName); - } - } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 1195ec59b86..9ae2a1b4d9d 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -23657,6 +23657,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/vararg"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); } + @TestMetadata("assigningArrayToVarargInAnnotation.kt") + public void testAssigningArrayToVarargInAnnotation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/vararg/assigningArrayToVarargInAnnotation.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + @TestMetadata("kt1978.kt") public void testKt1978() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/vararg/kt1978.kt");