Skip to content

Commit 0777fa7

Browse files
committed
Fix algorithm bug in paramIndices
1 parent 0291b8f commit 0777fa7

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,15 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
732732
/** If parameter `param` appears exactly once as an argument in `args`,
733733
* the singleton list consisting of its position in `args`, otherwise `Nil`.
734734
*/
735-
def paramIndices(param: untpd.ValDef, args: List[untpd.Tree], start: Int): List[Int] = args match {
736-
case arg :: args1 =>
737-
if (refersTo(arg, param))
738-
if (paramIndices(param, args1, start + 1).isEmpty) start :: Nil
739-
else Nil
740-
else paramIndices(param, args1, start + 1)
741-
case _ => Nil
735+
def paramIndices(param: untpd.ValDef, args: List[untpd.Tree]): List[Int] = {
736+
def loop(args: List[untpd.Tree], start: Int): List[Int] = args match {
737+
case arg :: args1 =>
738+
val others = loop(args1, start + 1)
739+
if (refersTo(arg, param)) start :: others else others
740+
case _ => Nil
741+
}
742+
val allIndices = loop(args, 0)
743+
if (allIndices.length == 1) allIndices else Nil
742744
}
743745

744746
/** If function is of the form
@@ -752,7 +754,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
752754
def calleeType: Type = fnBody match {
753755
case Apply(expr, args) =>
754756
paramIndex = {
755-
for (param <- params; idx <- paramIndices(param, args, 0))
757+
for (param <- params; idx <- paramIndices(param, args))
756758
yield param.name -> idx
757759
}.toMap
758760
if (paramIndex.size == params.length)

0 commit comments

Comments
 (0)