From 3626b1df445f786c3198e8e5fe3f1fb80163dd81 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 28 Sep 2021 22:43:03 +0200 Subject: [PATCH] Psi2ir: remove support for disabling SamConversionPerArgument --- .../psi2ir/generators/ArgumentsGenerationUtils.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt index cd04fb13c26..b7a041ad321 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt @@ -43,12 +43,12 @@ import org.jetbrains.kotlin.psi2ir.intermediate.* import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor -import org.jetbrains.kotlin.resolve.calls.util.getSuperCallExpression -import org.jetbrains.kotlin.resolve.calls.util.isSafeCall import org.jetbrains.kotlin.resolve.calls.components.isArrayOrArrayLiteral import org.jetbrains.kotlin.resolve.calls.components.isVararg import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.tower.NewResolvedCallImpl +import org.jetbrains.kotlin.resolve.calls.util.getSuperCallExpression +import org.jetbrains.kotlin.resolve.calls.util.isSafeCall import org.jetbrains.kotlin.resolve.scopes.receivers.* import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.typeUtil.isUnit @@ -552,7 +552,6 @@ fun StatementGenerator.generateSamConversionForValueArgumentsIfRequired(call: Ca "$originalDescriptor has ${originalDescriptor.typeParameters}" } - val partialSamConversionIsSupported = context.languageVersionSettings.supportsFeature(LanguageFeature.SamConversionPerArgument) val resolvedCallArguments = resolvedCall.safeAs>()?.argumentMappingByOriginal?.values assert(resolvedCallArguments == null || resolvedCallArguments.size == underlyingValueParameters.size) { "Mismatching resolved call arguments:\n" + @@ -562,7 +561,6 @@ fun StatementGenerator.generateSamConversionForValueArgumentsIfRequired(call: Ca (underlyingValueParameters zip resolvedCallArguments).any { (param, arg) -> param.isVararg && arg is ResolvedCallArgument.SimpleArgument && arg.callArgument.isArrayOrArrayLiteral() } - val expectSamConvertedArgumentToBeAvailableInResolvedCall = partialSamConversionIsSupported && !isArrayAssignedToVararg val substitutionContext = call.original.typeArguments.entries.associate { (typeParameterDescriptor, typeArgument) -> underlyingDescriptor.typeParameters[typeParameterDescriptor.index].typeConstructor to TypeProjectionImpl(typeArgument) @@ -573,12 +571,12 @@ fun StatementGenerator.generateSamConversionForValueArgumentsIfRequired(call: Ca val underlyingValueParameter: ValueParameterDescriptor = underlyingValueParameters[i] val expectedSamConversionTypesForVararg = - if (expectSamConvertedArgumentToBeAvailableInResolvedCall && resolvedCall is NewResolvedCallImpl<*>) { + if (!isArrayAssignedToVararg && resolvedCall is NewResolvedCallImpl<*>) { val arguments = resolvedCall.valueArguments[originalValueParameters[i]]?.arguments arguments?.map { resolvedCall.getExpectedTypeForSamConvertedArgument(it) } } else null - if (expectedSamConversionTypesForVararg?.all { it == null } != false) { + if (expectedSamConversionTypesForVararg == null || expectedSamConversionTypesForVararg.all { it == null }) { // When the method is `f(T)` with `T` = a SAM type, the substituted type is a SAM while the original is not; // when the method is `f(X)` with `T` = `out V` where `X` is a SAM type, the substituted type is `Nothing` // while the original is a SAM interface. Thus, if *either* of those is a SAM type then it's fine.