FIR: Fix overload resolution with defaults

This commit is contained in:
Denis Zharkov
2020-09-29 19:16:42 +03:00
parent 4964ff0019
commit 85b8673434
5 changed files with 15 additions and 9 deletions
@@ -129,7 +129,7 @@ abstract class AbstractConeCallConflictResolver(
//constructor.receiverTypeRef != null,
false,
constructor.valueParameters.any { it.isVararg },
constructor.valueParameters.count { it.defaultValue != null },
call.numDefaults,
constructor.isExpect,
false // TODO
)
@@ -142,7 +142,7 @@ abstract class AbstractConeCallConflictResolver(
computeParameterTypes(call, function),
function.receiverTypeRef != null,
function.valueParameters.any { it.isVararg },
function.valueParameters.count { it.defaultValue != null },
call.numDefaults,
function.isExpect,
false // TODO
)
@@ -103,6 +103,7 @@ class Candidate(
var usesSuspendConversion: Boolean = false
var argumentMapping: Map<FirExpression, FirValueParameter>? = null
var numDefaults: Int = 0
lateinit var typeArgumentMapping: TypeArgumentMapping
val postponedAtoms = mutableListOf<PostponedResolvedAtom>()
@@ -44,6 +44,10 @@ data class ArgumentMapping(
}
return argumentToParameterMapping
}
fun numDefaults(): Int {
return parameterToCallArgumentMap.values.count { it == ResolvedCallArgument.DefaultArgument }
}
}
private val EmptyArgumentMapping = ArgumentMapping(emptyMap(), emptyList())
@@ -171,6 +171,7 @@ internal object MapArguments : ResolutionStage() {
val mapping = context.bodyResolveComponents.mapArguments(callInfo.arguments, function, candidate.originScope)
candidate.argumentMapping = mapping.toArgumentToParameterMapping()
candidate.numDefaults = mapping.numDefaults()
mapping.diagnostics.forEach(sink::reportDiagnostic)
sink.yieldIfNeed()
@@ -1,9 +1,9 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A(x: String = "", y: String = "") {
constructor(x: String, y: String): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(x, y)
constructor(): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>("", "")
constructor(): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>("", "")
constructor(x: String, y: String): <!AMBIGUITY!>this<!>(x, y)
constructor(): <!AMBIGUITY!>this<!>("", "")
constructor(): <!AMBIGUITY!>this<!>("", "")
}
class B {
@@ -14,9 +14,9 @@ fun B(x: Int) {}
class Outer {
class A(x: String = "", y: String = "") {
constructor(x: String, y: String): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(x, y)
constructor(): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>("", "")
constructor(): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>("", "")
constructor(x: String, y: String): <!AMBIGUITY!>this<!>(x, y)
constructor(): <!AMBIGUITY!>this<!>("", "")
constructor(): <!AMBIGUITY!>this<!>("", "")
}
class B {
@@ -24,4 +24,4 @@ class Outer {
}
fun B(x: Int) {}
}
}