Psi2Ir: Fix SAM conversion with new inference

This commit is contained in:
Steven Schäfer
2020-08-21 11:21:51 +02:00
committed by Dmitry Petrov
parent 75891e860b
commit 44ffb1fb3e
8 changed files with 49 additions and 16 deletions
@@ -613,12 +613,13 @@ fun StatementGenerator.generateSamConversionForValueArgumentsIfRequired(call: Ca
for (i in underlyingValueParameters.indices) {
val underlyingValueParameter = underlyingValueParameters[i]
val expectedSamConversionTypesForVararg = ArrayList<KotlinType?>()
if (expectSamConvertedArgumentToBeAvailableInResolvedCall && resolvedCall is NewResolvedCallImpl<*>) {
val arguments = resolvedCall.valueArguments[originalValueParameters[i]]?.arguments ?: continue
arguments.mapTo(expectedSamConversionTypesForVararg) { resolvedCall.getExpectedTypeForSamConvertedArgument(it) }
if (expectedSamConversionTypesForVararg.all { it == null }) continue
} else {
val expectedSamConversionTypesForVararg =
if (expectSamConvertedArgumentToBeAvailableInResolvedCall && resolvedCall is NewResolvedCallImpl<*>) {
val arguments = resolvedCall.valueArguments[originalValueParameters[i]]?.arguments
arguments?.map { resolvedCall.getExpectedTypeForSamConvertedArgument(it) }
} else null
if (expectedSamConversionTypesForVararg?.all { it == null } != false) {
// 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<T>)` 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.
@@ -675,8 +676,7 @@ fun StatementGenerator.generateSamConversionForValueArgumentsIfRequired(call: Ca
).apply {
originalArgument.elements.mapIndexedTo(elements) { index, element ->
if (element is IrExpression) {
val samType = expectedSamConversionTypesForVararg[index]
if (samType != null)
if (expectedSamConversionTypesForVararg?.get(index) != null)
samConvertScalarExpression(element)
else
element
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
@@ -32,11 +31,6 @@ class ExternalDependenciesGenerator(
private val languageVersionSettings: LanguageVersionSettings
) {
fun generateUnboundSymbolsAsDependencies() {
if (languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) {
require(symbolTable.unboundTypeParameters.isEmpty()) {
"Unbound type parameters are forbidden: ${symbolTable.unboundTypeParameters}"
}
}
// There should be at most one DeclarationStubGenerator (none in closed world?)
irProviders.singleOrNull { it is DeclarationStubGenerator }?.let {
(it as DeclarationStubGenerator).unboundSymbolGeneration = true