Skip to content

Commit 903e6e5

Browse files
committed
Handle default arguments in later parameter sections.
Default arguments in later parameter sections are functions that take ealier arguments as parameters. When we just want to test whether a method is applicable, we don't keep track of these earlier arguments. Therefore, we always assume in this case that a default getter matches, if one was found.
1 parent 063579a commit 903e6e5

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ trait Applications extends Compatibility {
589589

590590
def tryDefault(n: Int, args1: List[Arg]): Unit = {
591591
val sym = methRef.symbol
592+
val testOnly = this.isInstanceOf[TestApplication[?]]
592593

593594
val defaultArg =
594595
if (isJavaAnnotConstr(sym)) {
@@ -604,12 +605,14 @@ trait Applications extends Compatibility {
604605
else
605606
EmptyTree
606607
}
607-
else defaultArgument(normalizedFun, n, this.isInstanceOf[TestApplication[?]])
608+
else defaultArgument(normalizedFun, n, testOnly)
608609

609610
def implicitArg = implicitArgTree(formal, appPos.span)
610611

611612
if !defaultArg.isEmpty then
612-
matchArgs(args1, addTyped(treeToArg(defaultArg)), n + 1)
613+
defaultArg.tpe.widen match
614+
case _: MethodOrPoly if testOnly => matchArgs(args1, formals1, n + 1)
615+
case _ => matchArgs(args1, addTyped(treeToArg(defaultArg)), n + 1)
613616
else if methodType.isContextualMethod && ctx.mode.is(Mode.ImplicitsEnabled) then
614617
matchArgs(args1, addTyped(treeToArg(implicitArg)), n + 1)
615618
else

project/MiMaFilters.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import com.typesafe.tools.mima.core._
33

44
object MiMaFilters {
55
val Library: Seq[ProblemFilter] = Seq(
6+
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.internal.MappedAlternative"),
67
)
78
}

tests/run/i15287.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def f(x: Char)(someParam: String): String = "a"
2+
def f(x: Char)(min: Boolean, max: Int = 4): String = "b"
3+
4+
@main def Test() = f('c')(false)

0 commit comments

Comments
 (0)