[NI] Fix SAM conversion for projected-out members
#KT-25290 Fixed
This commit is contained in:
+7
-1
@@ -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
|
||||
|
||||
+3
@@ -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
-1
@@ -1,6 +1,6 @@
|
||||
// !LANGUAGE: -NewInference
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
// FILE: example/Hello.java
|
||||
|
||||
|
||||
Reference in New Issue
Block a user