Skip to content

Commit f35c521

Browse files
committed
Change order of evaluation for default parameters
Explicitly given parameters are always evaluated before default parameters. Aligns with spec and Scala 2.
1 parent 50dc05c commit f35c521

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
817817
val ownerAcc = new TreeAccumulator[immutable.Set[Symbol]] {
818818
def apply(ss: immutable.Set[Symbol], tree: Tree)(using Context) = tree match {
819819
case tree: DefTree =>
820-
if (tree.symbol.exists) ss + tree.symbol.owner
821-
else ss
820+
val sym = tree.symbol
821+
if sym.exists && !sym.owner.is(Package) then ss + sym.owner else ss
822822
case _ =>
823823
foldOver(ss, tree)
824824
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ trait Applications extends Compatibility {
756756
val app1 =
757757
if (!success) app0.withType(UnspecifiedErrorType)
758758
else {
759-
if (!sameSeq(args, orderedArgs.dropWhile(_ eq EmptyTree)) && !isJavaAnnotConstr(methRef.symbol)) {
759+
if !sameSeq(args, orderedArgs) && !isJavaAnnotConstr(methRef.symbol) then
760760
// need to lift arguments to maintain evaluation order in the
761761
// presence of argument reorderings.
762762

@@ -787,7 +787,7 @@ trait Applications extends Compatibility {
787787
argDefBuf.zip(impureArgIndices), (arg, idx) => originalIndex(idx)).map(_._1)
788788
}
789789
liftedDefs ++= orderedArgDefs
790-
}
790+
end if
791791
if (sameSeq(typedArgs, args)) // trick to cut down on tree copying
792792
typedArgs = args.asInstanceOf[List[Tree]]
793793
assignType(app0, normalizedFun, typedArgs)

compiler/test/dotc/pos-test-pickling.blacklist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,6 @@ i9793.scala
6060

6161
# lazy_implicit symbol has different position after pickling
6262
i8182.scala
63+
64+
# local lifted value in annotation argument has different position after pickling
65+
i2797a

tests/run/i11571.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
17
2+
42

tests/run/i11571.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import util.chaining.scalaUtilChainingOps
2+
object Test extends App {
3+
def x = 42.tap(println(_))
4+
def y = 27.tap(println(_))
5+
def z = 17.tap(println(_))
6+
def f(i: Int = x, j: Int = y) = i + j
7+
f(j = z)
8+
}

0 commit comments

Comments
 (0)