Allow use expression of array type as named argument for vararg

This commit is contained in:
Dmitriy Novozhilov
2019-12-17 13:04:42 +03:00
parent 0cb48999ff
commit ee36fb903f
15 changed files with 253 additions and 8 deletions
@@ -52,7 +52,11 @@ val ReceiverValueWithSmartCastInfo.stableType: UnwrappedType
}
internal fun KotlinCallArgument.getExpectedType(parameter: ParameterDescriptor, languageVersionSettings: LanguageVersionSettings) =
if (this.isSpread || this.isArrayAssignedAsNamedArgumentInAnnotation(parameter, languageVersionSettings)) {
if (
this.isSpread ||
this.isArrayAssignedAsNamedArgumentInAnnotation(parameter, languageVersionSettings) ||
this.isArrayAssignedAsNamedArgumentInFunction(parameter, languageVersionSettings)
) {
parameter.type.unwrap()
} else {
parameter.safeAs<ValueParameterDescriptor>()?.varargElementType?.unwrap() ?: parameter.type.unwrap()
@@ -120,6 +124,17 @@ private fun KotlinCallArgument.isArrayAssignedAsNamedArgumentInAnnotation(
return isParameterOfAnnotation(parameter) && this.isArrayOrArrayLiteral()
}
private fun KotlinCallArgument.isArrayAssignedAsNamedArgumentInFunction(
parameter: ParameterDescriptor,
languageVersionSettings: LanguageVersionSettings
): Boolean {
if (!languageVersionSettings.supportsFeature(LanguageFeature.AllowAssigningArrayElementsToVarargsInNamedFormForFunctions)) return false
if (this.argumentName == null || !parameter.isVararg) return false
return this.isArrayOrArrayLiteral()
}
private fun KotlinCallArgument.isArrayOrArrayLiteral(): Boolean {
if (this is CollectionLiteralKotlinCallArgument) return true
if (this !is SimpleKotlinCallArgument) return false