Skip to content

Commit 50c6c86

Browse files
committed
Fix vals and add comments
1 parent 733673f commit 50c6c86

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -613,21 +613,25 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
613613
liftFun()
614614

615615
// lift arguments in the definition order
616-
val argDefBuff = mutable.ListBuffer.empty[Tree]
617-
typedArgs = liftArgs(argDefBuff, methType, typedArgs)
618-
619-
def orderedArgDefs = {
620-
val impureArgs = typedArgBuf.filterNot { // pure are not lifted by liftArgs
616+
val argDefBuf = mutable.ListBuffer.empty[Tree]
617+
typedArgs = liftArgs(argDefBuf, methType, typedArgs)
618+
619+
// Lifted arguments ordered based on the original order of typedArgBuf and
620+
// with all non explicit default parameters at the end in declaration order.
621+
val orderedArgDefs = {
622+
// List of original arguments that are lifted by liftArgs
623+
val impureArgs = typedArgBuf.filterNot {
621624
case NamedArg(_, arg) => isPureExpr(arg)
622625
case arg => isPureExpr(arg)
623626
}
624-
var defaultParamIndex = args.size
627+
val defaultParamIndex = args.size
625628
// Mapping of index of each `liftable` into original args ordering
626629
val indices = impureArgs.map { arg =>
627630
val idx = args.indexOf(arg)
628-
if (idx >= 0) idx else defaultParamIndex // assuming stable sorting
631+
if (idx >= 0) idx // original index skipping pure agruments
632+
else defaultParamIndex // assuming stable sorting all will remain in the end with the same order
629633
}
630-
scala.util.Sorting.stableSort[(Tree, Int), Int](argDefBuff zip indices, x => x._2).map(_._1)
634+
scala.util.Sorting.stableSort[(Tree, Int), Int](argDefBuf zip indices, x => x._2).map(_._1)
631635
}
632636

633637
liftedDefs ++= orderedArgDefs

0 commit comments

Comments
 (0)