[NI] Fix SAM conversion for projected-out members

#KT-25290 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-04-27 03:41:12 +03:00
parent e3fe1bcf7c
commit fa50d66afe
3 changed files with 11 additions and 2 deletions
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.resolve.scopes.SyntheticScope
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.findCorrespondingSupertype
import org.jetbrains.kotlin.types.typeUtil.isNothing
import kotlin.properties.Delegates
interface SamAdapterExtensionFunctionDescriptor : FunctionDescriptor, FunctionInterfaceAdapterExtensionFunctionDescriptor {
@@ -106,7 +107,9 @@ class SamAdapterFunctionsScope(
var result: SmartList<FunctionDescriptor>? = null
for (type in receiverTypes) {
for (function in type.memberScope.getContributedFunctions(name, location)) {
if (samViaSyntheticScopeDisabled && !function.shouldGenerateCandidateForVarargAfterSamAndHasVararg) continue
if (samViaSyntheticScopeDisabled && !function.hasNothingTypeInParameters) {
if (!function.shouldGenerateCandidateForVarargAfterSamAndHasVararg) continue
}
val extension = extensionForFunction(function.original)?.substituteForReceiverType(type)
if (extension != null) {
@@ -134,6 +137,9 @@ class SamAdapterFunctionsScope(
private val FunctionDescriptor.shouldGenerateCandidateForVarargAfterSamAndHasVararg
get() = shouldGenerateCandidateForVarargAfterSam && valueParameters.lastOrNull()?.isVararg == true
private val FunctionDescriptor.hasNothingTypeInParameters
get() = valueParameters.any { it.type.isNothing() && !it.original.type.isNothing() }
private fun FunctionDescriptor.substituteForReceiverType(receiverType: KotlinType): FunctionDescriptor? {
val containingClass = containingDeclaration as? ClassDescriptor ?: return null
val correspondingSupertype = findCorrespondingSupertype(receiverType, containingClass.defaultType) ?: return null
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.types.model.KotlinTypeMarker
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
import org.jetbrains.kotlin.types.model.typeConstructor
import org.jetbrains.kotlin.types.typeUtil.contains
import org.jetbrains.kotlin.types.typeUtil.isNothing
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
import org.jetbrains.kotlin.types.typeUtil.makeNullable
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -500,6 +501,8 @@ private fun KotlinResolutionCandidate.getExpectedTypeWithSAMConversion(
!callComponents.languageVersionSettings.supportsFeature(LanguageFeature.ProhibitVarargAsArrayAfterSamArgument)
if (generatingAdditionalSamCandidateIsEnabled) return null
if (candidateParameter.type.isNothing()) return null
val samConversionOracle = callComponents.samConversionOracle
if (!callComponents.languageVersionSettings.supportsFeature(LanguageFeature.SamConversionForKotlinFunctions)) {
if (!samConversionOracle.shouldRunSamConversionForFunction(resolvedCall.candidateDescriptor)) return null
@@ -1,6 +1,6 @@
// !LANGUAGE: -NewInference
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM_IR
// FILE: example/Hello.java