FIR: resolve conflicts around SAM calls properly
This commit is contained in:
+6
-4
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.resolve.calls.jvm
|
||||
import org.jetbrains.kotlin.fir.containingClass
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
|
||||
import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.AbstractConeCallConflictResolver
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.Candidate
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents
|
||||
@@ -19,8 +20,9 @@ import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator
|
||||
// like emptyArray() from intrinsics and built-ins
|
||||
class ConeEquivalentCallConflictResolver(
|
||||
specificityComparator: TypeSpecificityComparator,
|
||||
inferenceComponents: InferenceComponents
|
||||
) : AbstractConeCallConflictResolver(specificityComparator, inferenceComponents) {
|
||||
inferenceComponents: InferenceComponents,
|
||||
transformerComponents: BodyResolveComponents
|
||||
) : AbstractConeCallConflictResolver(specificityComparator, inferenceComponents, transformerComponents) {
|
||||
override fun chooseMaximallySpecificCandidates(
|
||||
candidates: Set<Candidate>,
|
||||
discriminateGenerics: Boolean,
|
||||
@@ -64,8 +66,8 @@ class ConeEquivalentCallConflictResolver(
|
||||
}
|
||||
val firstSignature = createFlatSignature(firstCandidate, first)
|
||||
val secondSignature = createFlatSignature(secondCandidate, second)
|
||||
return compareCallsByUsedArguments(firstSignature, secondSignature, false) &&
|
||||
compareCallsByUsedArguments(secondSignature, firstSignature, false)
|
||||
return compareCallsByUsedArguments(firstSignature, secondSignature, discriminateGenerics = false, useOriginalSamTypes = false) &&
|
||||
compareCallsByUsedArguments(secondSignature, firstSignature, discriminateGenerics = false, useOriginalSamTypes = false)
|
||||
}
|
||||
|
||||
private fun createFlatSignature(call: Candidate, declaration: FirCallableDeclaration): FlatSignature<Candidate> {
|
||||
|
||||
+8
-5
@@ -6,11 +6,13 @@
|
||||
package org.jetbrains.kotlin.fir.resolve.calls.jvm
|
||||
|
||||
import org.jetbrains.kotlin.fir.NoMutableState
|
||||
import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.ConeCallConflictResolverFactory
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.ConeCompositeConflictResolver
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.ConeIntegerOperatorConflictResolver
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.ConeOverloadConflictResolver
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirAbstractBodyResolveTransformer
|
||||
import org.jetbrains.kotlin.fir.types.typeContext
|
||||
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmTypeSpecificityComparator
|
||||
@@ -19,14 +21,15 @@ import org.jetbrains.kotlin.resolve.jvm.JvmTypeSpecificityComparator
|
||||
object JvmCallConflictResolverFactory : ConeCallConflictResolverFactory() {
|
||||
override fun create(
|
||||
typeSpecificityComparator: TypeSpecificityComparator,
|
||||
components: InferenceComponents
|
||||
components: InferenceComponents,
|
||||
transformerComponents: BodyResolveComponents
|
||||
): ConeCompositeConflictResolver {
|
||||
val specificityComparator = JvmTypeSpecificityComparator(components.session.typeContext)
|
||||
return ConeCompositeConflictResolver(
|
||||
ConeOverloadConflictResolver(specificityComparator, components),
|
||||
ConeEquivalentCallConflictResolver(specificityComparator, components),
|
||||
JvmPlatformOverloadsConflictResolver(specificityComparator, components),
|
||||
ConeIntegerOperatorConflictResolver(specificityComparator, components)
|
||||
ConeOverloadConflictResolver(specificityComparator, components, transformerComponents),
|
||||
ConeEquivalentCallConflictResolver(specificityComparator, components, transformerComponents),
|
||||
JvmPlatformOverloadsConflictResolver(specificityComparator, components, transformerComponents),
|
||||
ConeIntegerOperatorConflictResolver(specificityComparator, components, transformerComponents)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -10,15 +10,18 @@ import org.jetbrains.kotlin.fir.containingClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirField
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.AbstractConeCallConflictResolver
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.Candidate
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirAbstractBodyResolveTransformer
|
||||
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator
|
||||
|
||||
class JvmPlatformOverloadsConflictResolver(
|
||||
specificityComparator: TypeSpecificityComparator,
|
||||
inferenceComponents: InferenceComponents
|
||||
) : AbstractConeCallConflictResolver(specificityComparator, inferenceComponents) {
|
||||
inferenceComponents: InferenceComponents,
|
||||
transformerComponents: BodyResolveComponents
|
||||
) : AbstractConeCallConflictResolver(specificityComparator, inferenceComponents, transformerComponents) {
|
||||
override fun chooseMaximallySpecificCandidates(
|
||||
candidates: Set<Candidate>,
|
||||
discriminateGenerics: Boolean,
|
||||
|
||||
@@ -68,7 +68,7 @@ class FirCallResolver(
|
||||
)
|
||||
|
||||
val conflictResolver: ConeCallConflictResolver =
|
||||
session.callConflictResolverFactory.create(TypeSpecificityComparator.NONE, session.inferenceComponents)
|
||||
session.callConflictResolverFactory.create(TypeSpecificityComparator.NONE, session.inferenceComponents, components)
|
||||
|
||||
@PrivateForInline
|
||||
var needTransformArguments: Boolean = true
|
||||
|
||||
+52
-35
@@ -7,6 +7,8 @@ package org.jetbrains.kotlin.fir.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
|
||||
import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
|
||||
import org.jetbrains.kotlin.fir.resolve.FirSamResolver
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
@@ -17,8 +19,12 @@ import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
|
||||
abstract class AbstractConeCallConflictResolver(
|
||||
private val specificityComparator: TypeSpecificityComparator,
|
||||
protected val inferenceComponents: InferenceComponents
|
||||
protected val inferenceComponents: InferenceComponents,
|
||||
private val transformerComponents: BodyResolveComponents
|
||||
) : ConeCallConflictResolver() {
|
||||
|
||||
private val samResolver: FirSamResolver get() = transformerComponents.samResolver
|
||||
|
||||
/**
|
||||
* Returns `true` if [call1] is definitely more or equally specific [call2],
|
||||
* `false` otherwise.
|
||||
@@ -26,7 +32,8 @@ abstract class AbstractConeCallConflictResolver(
|
||||
protected fun compareCallsByUsedArguments(
|
||||
call1: FlatSignature<Candidate>,
|
||||
call2: FlatSignature<Candidate>,
|
||||
discriminateGenerics: Boolean
|
||||
discriminateGenerics: Boolean,
|
||||
useOriginalSamTypes: Boolean
|
||||
): Boolean {
|
||||
if (discriminateGenerics) {
|
||||
val isGeneric1 = call1.isGeneric
|
||||
@@ -48,7 +55,8 @@ abstract class AbstractConeCallConflictResolver(
|
||||
call1,
|
||||
call2,
|
||||
SpecificityComparisonWithNumerics,
|
||||
specificityComparator
|
||||
specificityComparator,
|
||||
useOriginalSamTypes
|
||||
)
|
||||
}
|
||||
|
||||
@@ -113,44 +121,44 @@ abstract class AbstractConeCallConflictResolver(
|
||||
|
||||
protected fun createFlatSignature(call: Candidate, variable: FirVariable): FlatSignature<Candidate> {
|
||||
return FlatSignature(
|
||||
call,
|
||||
(variable as? FirProperty)?.typeParameters?.map { it.symbol.toLookupTag() }.orEmpty(),
|
||||
computeSignatureTypes(call, variable),
|
||||
variable.receiverTypeRef != null,
|
||||
variable.contextReceivers.size,
|
||||
false,
|
||||
0,
|
||||
(variable as? FirProperty)?.isExpect == true,
|
||||
false // TODO
|
||||
origin = call,
|
||||
typeParameters = (variable as? FirProperty)?.typeParameters?.map { it.symbol.toLookupTag() }.orEmpty(),
|
||||
valueParameterTypes = computeSignatureTypes(call, variable),
|
||||
hasExtensionReceiver = variable.receiverTypeRef != null,
|
||||
contextReceiverCount = variable.contextReceivers.size,
|
||||
hasVarargs = false,
|
||||
numDefaults = 0,
|
||||
isExpect = (variable as? FirProperty)?.isExpect == true,
|
||||
isSyntheticMember = false // TODO
|
||||
)
|
||||
}
|
||||
|
||||
protected fun createFlatSignature(call: Candidate, constructor: FirConstructor): FlatSignature<Candidate> {
|
||||
return FlatSignature(
|
||||
call,
|
||||
constructor.typeParameters.map { it.symbol.toLookupTag() },
|
||||
computeSignatureTypes(call, constructor),
|
||||
origin = call,
|
||||
typeParameters = constructor.typeParameters.map { it.symbol.toLookupTag() },
|
||||
valueParameterTypes = computeSignatureTypes(call, constructor),
|
||||
//constructor.receiverTypeRef != null,
|
||||
false,
|
||||
constructor.contextReceivers.size,
|
||||
constructor.valueParameters.any { it.isVararg },
|
||||
call.numDefaults,
|
||||
constructor.isExpect,
|
||||
false // TODO
|
||||
hasExtensionReceiver = false,
|
||||
contextReceiverCount = constructor.contextReceivers.size,
|
||||
hasVarargs = constructor.valueParameters.any { it.isVararg },
|
||||
numDefaults = call.numDefaults,
|
||||
isExpect = constructor.isExpect,
|
||||
isSyntheticMember = false // TODO
|
||||
)
|
||||
}
|
||||
|
||||
protected fun createFlatSignature(call: Candidate, function: FirSimpleFunction): FlatSignature<Candidate> {
|
||||
return FlatSignature(
|
||||
call,
|
||||
function.typeParameters.map { it.symbol.toLookupTag() },
|
||||
computeSignatureTypes(call, function),
|
||||
function.receiverTypeRef != null,
|
||||
function.contextReceivers.size,
|
||||
function.valueParameters.any { it.isVararg },
|
||||
call.numDefaults,
|
||||
function.isExpect,
|
||||
false // TODO
|
||||
origin = call,
|
||||
typeParameters = function.typeParameters.map { it.symbol.toLookupTag() },
|
||||
valueParameterTypes = computeSignatureTypes(call, function),
|
||||
hasExtensionReceiver = function.receiverTypeRef != null,
|
||||
contextReceiverCount = function.contextReceivers.size,
|
||||
hasVarargs = function.valueParameters.any { it.isVararg },
|
||||
numDefaults = call.numDefaults,
|
||||
isExpect = function.isExpect,
|
||||
isSyntheticMember = false // TODO
|
||||
)
|
||||
}
|
||||
|
||||
@@ -163,19 +171,28 @@ abstract class AbstractConeCallConflictResolver(
|
||||
private fun computeSignatureTypes(
|
||||
call: Candidate,
|
||||
called: FirCallableDeclaration
|
||||
): List<ConeKotlinType> {
|
||||
): List<TypeWithConversion> {
|
||||
return buildList {
|
||||
addIfNotNull(called.receiverTypeRef?.coneType)
|
||||
addIfNotNull(called.receiverTypeRef?.coneType?.let { TypeWithConversion(it) })
|
||||
val typeForCallableReference = call.resultingTypeForCallableReference
|
||||
if (typeForCallableReference != null) {
|
||||
// Return type isn't needed here v
|
||||
typeForCallableReference.typeArguments.dropLast(1)
|
||||
.mapTo(this) {
|
||||
(it as ConeKotlinType).removeTypeVariableTypes(inferenceComponents.session.typeContext)
|
||||
TypeWithConversion((it as ConeKotlinType).removeTypeVariableTypes(inferenceComponents.session.typeContext))
|
||||
}
|
||||
} else {
|
||||
called.contextReceivers.mapTo(this) { it.typeRef.coneType }
|
||||
call.argumentMapping?.mapTo(this) { it.value.argumentType() }
|
||||
called.contextReceivers.mapTo(this) { TypeWithConversion(it.typeRef.coneType) }
|
||||
call.argumentMapping?.mapTo(this) { (_, parameter) ->
|
||||
val argumentType = parameter.argumentType()
|
||||
if (!call.usesSAM) {
|
||||
TypeWithConversion(argumentType)
|
||||
} else {
|
||||
val functionType = samResolver.getFunctionTypeForPossibleSamType(argumentType)?.second
|
||||
if (functionType == null) TypeWithConversion(argumentType)
|
||||
else TypeWithConversion(functionType, argumentType)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,12 +507,10 @@ private fun Candidate.getExpectedTypeWithSAMConversion(
|
||||
// TODO: resolvedCall.registerArgumentWithSamConversion(argument, SamConversionDescription(convertedTypeByOriginal, convertedTypeByCandidate!!))
|
||||
|
||||
val expectedFunctionType = context.bodyResolveComponents.samResolver.getFunctionTypeForPossibleSamType(candidateExpectedType)
|
||||
?: return null
|
||||
return runIf(argument.isFunctional(session, scopeSession, expectedFunctionType)) {
|
||||
expectedFunctionType.apply {
|
||||
// Even though the `expectedFunctionalType` could be `null`, we should mark the flag to indicate that the argument is a
|
||||
// functional type. That will help avoid ambiguous `invoke` resolutions. See KT-39824
|
||||
usesSAM = true
|
||||
}
|
||||
usesSAM = true
|
||||
expectedFunctionType
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.FirSessionComponent
|
||||
import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents
|
||||
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator
|
||||
|
||||
@@ -25,7 +26,11 @@ abstract class ConeCallConflictResolver {
|
||||
}
|
||||
|
||||
abstract class ConeCallConflictResolverFactory : FirSessionComponent {
|
||||
abstract fun create(typeSpecificityComparator: TypeSpecificityComparator, components: InferenceComponents): ConeCallConflictResolver
|
||||
abstract fun create(
|
||||
typeSpecificityComparator: TypeSpecificityComparator,
|
||||
components: InferenceComponents,
|
||||
transformerComponents: BodyResolveComponents
|
||||
): ConeCallConflictResolver
|
||||
}
|
||||
|
||||
val FirSession.callConflictResolverFactory: ConeCallConflictResolverFactory by FirSession.sessionComponentAccessor()
|
||||
+4
-2
@@ -5,14 +5,16 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.isWrappedIntegerOperator
|
||||
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator
|
||||
|
||||
class ConeIntegerOperatorConflictResolver(
|
||||
specificityComparator: TypeSpecificityComparator,
|
||||
inferenceComponents: InferenceComponents
|
||||
) : AbstractConeCallConflictResolver(specificityComparator, inferenceComponents) {
|
||||
inferenceComponents: InferenceComponents,
|
||||
transformerComponents: BodyResolveComponents
|
||||
) : AbstractConeCallConflictResolver(specificityComparator, inferenceComponents, transformerComponents) {
|
||||
override fun chooseMaximallySpecificCandidates(
|
||||
candidates: Set<Candidate>,
|
||||
discriminateGenerics: Boolean,
|
||||
|
||||
+16
-6
@@ -10,9 +10,11 @@ import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
||||
import org.jetbrains.kotlin.fir.render
|
||||
import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.ConeTypeParameterBasedTypeVariable
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirAbstractBodyResolveTransformer
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl
|
||||
@@ -29,8 +31,9 @@ typealias CandidateSignature = FlatSignature<Candidate>
|
||||
|
||||
class ConeOverloadConflictResolver(
|
||||
specificityComparator: TypeSpecificityComparator,
|
||||
inferenceComponents: InferenceComponents
|
||||
) : AbstractConeCallConflictResolver(specificityComparator, inferenceComponents) {
|
||||
inferenceComponents: InferenceComponents,
|
||||
transformerComponents: BodyResolveComponents
|
||||
) : AbstractConeCallConflictResolver(specificityComparator, inferenceComponents, transformerComponents) {
|
||||
|
||||
override fun chooseMaximallySpecificCandidates(
|
||||
candidates: Set<Candidate>,
|
||||
@@ -123,12 +126,18 @@ class ConeOverloadConflictResolver(
|
||||
}
|
||||
}
|
||||
|
||||
val filtered = candidates.filterTo(mutableSetOf()) { it.usesSAM }
|
||||
if (filtered.isNotEmpty()) {
|
||||
findMaximallySpecificCall(candidates, discriminateGenerics = false, useOriginalSamTypes = true)?.let { return setOf(it) }
|
||||
}
|
||||
|
||||
return candidates
|
||||
}
|
||||
|
||||
private fun findMaximallySpecificCall(
|
||||
candidates: Set<Candidate>,
|
||||
discriminateGenerics: Boolean
|
||||
discriminateGenerics: Boolean,
|
||||
useOriginalSamTypes: Boolean = false
|
||||
): Candidate? {
|
||||
if (candidates.size <= 1) return candidates.singleOrNull()
|
||||
|
||||
@@ -138,7 +147,7 @@ class ConeOverloadConflictResolver(
|
||||
|
||||
val bestCandidatesByParameterTypes = candidateSignatures.filter { signature ->
|
||||
candidateSignatures.all { other ->
|
||||
signature === other || isNotLessSpecificCallWithArgumentMapping(signature, other, discriminateGenerics)
|
||||
signature === other || isNotLessSpecificCallWithArgumentMapping(signature, other, discriminateGenerics, useOriginalSamTypes)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,9 +160,10 @@ class ConeOverloadConflictResolver(
|
||||
private fun isNotLessSpecificCallWithArgumentMapping(
|
||||
call1: CandidateSignature,
|
||||
call2: CandidateSignature,
|
||||
discriminateGenerics: Boolean
|
||||
discriminateGenerics: Boolean,
|
||||
useOriginalSamTypes: Boolean = false
|
||||
): Boolean {
|
||||
return compareCallsByUsedArguments(call1, call2, discriminateGenerics)
|
||||
return compareCallsByUsedArguments(call1, call2, discriminateGenerics, useOriginalSamTypes)
|
||||
}
|
||||
|
||||
private fun List<CandidateSignature>.exactMaxWith(): CandidateSignature? {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// FIR status: OVERLOAD_RESOLUTION_AMBIGUITY on sub.foo {}
|
||||
// WITH_STDLIB
|
||||
// MODULE: lib
|
||||
// FILE: Super.java
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
// FULL_JDK
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND_FIR_MULTI_MODULE: JVM_IR JVM_IR_SERIALIZE
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: 1.kt
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
// FULL_JDK
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND_FIR_MULTI_MODULE: JVM_IR JVM_IR_SERIALIZE
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: 1.kt
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
// FULL_JDK
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND_FIR_MULTI_MODULE: JVM_IR JVM_IR_SERIALIZE
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: 1.kt
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// FULL_JDK
|
||||
// NO_CHECK_LAMBDA_INLINING
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND_FIR_MULTI_MODULE: JVM_IR JVM_IR_SERIALIZE
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: 1.kt
|
||||
|
||||
|
||||
+1
-1
@@ -6,4 +6,4 @@ object X2
|
||||
fun <T1> foo(x: T1, f: (T1) -> T1) = X1
|
||||
fun <T2> foo(xf: () -> T2, f: (T2) -> T2) = X2
|
||||
|
||||
val test: X2 = foo({ 0 }, { it -> it + 1 })
|
||||
val test: X2 = <!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>({ 0 }, { it -> it + 1 })
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
// !LANGUAGE: +EliminateAmbiguitiesOnInheritedSamInterfaces
|
||||
// !CHECK_TYPE
|
||||
// FILE: Fn.java
|
||||
public interface Fn<T, R> {
|
||||
R apply(T t);
|
||||
}
|
||||
|
||||
// FILE: Fn2.java
|
||||
public interface Fn2<T, R> extends Fn<T, R> {}
|
||||
|
||||
// FILE: J.java
|
||||
public interface J {
|
||||
String foo(Fn<String, Object> f, Object o);
|
||||
int foo(Fn<Object, Object> f, String s); // (Any) -> Any <: (String) -> Any <=> String <: Any
|
||||
|
||||
String bas(Fn<Object, Object> f, Object o);
|
||||
int bas(Fn<Object, String> f, String s); // (Any) -> String <: (Any) -> Any <=> String <: Any
|
||||
|
||||
String bar(Fn<String, Object> f);
|
||||
int bar(Fn2<String, Object> f); // Fn2 seems more specific one even function type same
|
||||
}
|
||||
|
||||
// FILE: 1.kt
|
||||
fun test(j: J) {
|
||||
j.<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>({ <!UNRESOLVED_REFERENCE!>it<!> checkType { _<Any>() }; "" }, "") <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<Int>() }
|
||||
|
||||
j.<!OVERLOAD_RESOLUTION_AMBIGUITY!>bas<!>({ <!UNRESOLVED_REFERENCE!>it<!> checkType { _<Any>() }; "" }, "") <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<Int>() }
|
||||
|
||||
j.bar { it checkType { _<String>() }; "" } checkType { _<Int>() }
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +EliminateAmbiguitiesOnInheritedSamInterfaces
|
||||
// !CHECK_TYPE
|
||||
// FILE: Fn.java
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
// !LANGUAGE: +EliminateAmbiguitiesOnInheritedSamInterfaces +SamConversionForKotlinFunctions +SamConversionPerArgument
|
||||
// !CHECK_TYPE
|
||||
// FILE: Fn.java
|
||||
public interface Fn<T, R> {
|
||||
R apply(T t);
|
||||
}
|
||||
|
||||
// FILE: Fn2.java
|
||||
public interface Fn2<T, R> extends Fn<T, R> {}
|
||||
|
||||
// FILE: 1.kt
|
||||
interface K {
|
||||
fun foo(f: Fn<String, Any>): String
|
||||
fun foo(f: Fn<Any, Any>): Int
|
||||
|
||||
fun bas(f: Fn<Any, Any>): String
|
||||
fun bas(f: Fn<Any, String>): Int
|
||||
|
||||
fun bar(f: Fn<String, Any>): String
|
||||
fun bar(f: Fn2<String, Any>): Int
|
||||
}
|
||||
|
||||
fun test(k: K) {
|
||||
k.<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!> { <!UNRESOLVED_REFERENCE!>it<!> checkType { _<Any>() }; "" } <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<Int>() }
|
||||
|
||||
k.<!OVERLOAD_RESOLUTION_AMBIGUITY!>bas<!> { <!UNRESOLVED_REFERENCE!>it<!> checkType { _<Any?>() }; "" } <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<Int>() }
|
||||
|
||||
k.bar { it checkType { _<String>() }; "" } checkType { _<Int>() }
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +EliminateAmbiguitiesOnInheritedSamInterfaces +SamConversionForKotlinFunctions +SamConversionPerArgument
|
||||
// !CHECK_TYPE
|
||||
// FILE: Fn.java
|
||||
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
// FILE: StaticOverrides.java
|
||||
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
|
||||
public class StaticOverrides {
|
||||
public static class A {
|
||||
public static int foo(Runnable x) { return 0; }
|
||||
public static boolean foo(Function0<Unit> x) { return true; }
|
||||
}
|
||||
|
||||
public static class B {
|
||||
public static String foo(Runnable x) { return ""; }
|
||||
}
|
||||
|
||||
public static class C extends A {
|
||||
public static String foo(Runnable x) { return ""; }
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test() {
|
||||
StaticOverrides.A.<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!> {} <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<Boolean>() }
|
||||
StaticOverrides.B.foo {} checkType { _<String>() }
|
||||
StaticOverrides.C.<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!> {} <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<Boolean>() }
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !CHECK_TYPE
|
||||
|
||||
// FILE: StaticOverrides.java
|
||||
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
|
||||
// FILE: Foo.java
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
|
||||
class Foo {
|
||||
interface FObject<T> {
|
||||
void invoke(T i);
|
||||
}
|
||||
|
||||
public String foo(FObject<Integer> f) { return ""; }
|
||||
public int foo(Function1<Integer, Unit> f) { return 1; }
|
||||
|
||||
public String bar(FObject<Object> f) { return ""; }
|
||||
public int bar(Function1<Integer, Unit> f) { return 1; }
|
||||
}
|
||||
|
||||
// FILE: 1.kt
|
||||
fun test() {
|
||||
Foo().<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!> {} <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<Int>() }
|
||||
Foo().<!OVERLOAD_RESOLUTION_AMBIGUITY!>bar<!> {} <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<String>() }
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
|
||||
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
|
||||
// FILE: Foo.java
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
|
||||
public class Foo {
|
||||
interface FObject {
|
||||
void invoke(Object i);
|
||||
}
|
||||
|
||||
public String test(FObject f) { return ""; }
|
||||
public int test(Function1<Integer, Unit> f) { return 1; }
|
||||
}
|
||||
|
||||
// FILE: 1.kt
|
||||
fun bar() {
|
||||
Foo().<!OVERLOAD_RESOLUTION_AMBIGUITY!>test<!> {} <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<String>() }
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user