Skip to content

Commit c701cbb

Browse files
committed
Avoid some argument reorderings
Avoid reordering arguments if all explicitly given arguments are pure. In that case they can be freely interspersed with default getters.
1 parent f35c521 commit c701cbb

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,13 +750,23 @@ trait Applications extends Compatibility {
750750
}
751751
private def sameSeq[T <: Trees.Tree[?]](xs: List[T], ys: List[T]): Boolean = firstDiff(xs, ys) < 0
752752

753+
/** An argument is safe if it is a pure expression or a default getter call
754+
* If all arguments are safe, no reordering is necessary
755+
*/
756+
def isSafeArg(arg: Tree) =
757+
isPureExpr(arg)
758+
|| arg.isInstanceOf[RefTree | Apply | TypeApply] && arg.symbol.name.is(DefaultGetterName)
759+
753760
val result: Tree = {
754761
var typedArgs = typedArgBuf.toList
755762
def app0 = cpy.Apply(app)(normalizedFun, typedArgs) // needs to be a `def` because typedArgs can change later
756763
val app1 =
757764
if (!success) app0.withType(UnspecifiedErrorType)
758765
else {
759-
if !sameSeq(args, orderedArgs) && !isJavaAnnotConstr(methRef.symbol) then
766+
if !sameSeq(args, orderedArgs)
767+
&& !isJavaAnnotConstr(methRef.symbol)
768+
&& !typedArgs.forall(isSafeArg)
769+
then
760770
// need to lift arguments to maintain evaluation order in the
761771
// presence of argument reorderings.
762772

0 commit comments

Comments
 (0)