Skip to content

Commit a9972cc

Browse files
committed
Merge pull request scala#2611 from retronym/ticket/6481
SI-6841 Fix bug at the intersection of DelayedInit and named args
2 parents cb9edc9 + 608f577 commit a9972cc

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/compiler/scala/tools/nsc/transform/Constructors.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,10 @@ abstract class Constructors extends Transform with ast.TreeDSL {
523523

524524
/** Return a pair consisting of (all statements up to and including superclass and trait constr calls, rest) */
525525
def splitAtSuper(stats: List[Tree]) = {
526-
def isConstr(tree: Tree) = (tree.symbol ne null) && tree.symbol.isConstructor
526+
def isConstr(tree: Tree): Boolean = tree match {
527+
case Block(_, expr) => isConstr(expr) // SI-6481 account for named argument blocks
528+
case _ => (tree.symbol ne null) && tree.symbol.isConstructor
529+
}
527530
val (pre, rest0) = stats span (!isConstr(_))
528531
val (supercalls, rest) = rest0 span (isConstr(_))
529532
(pre ::: supercalls, rest)

test/files/run/t6481.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
delayed init
2+
new foo(1, 2)
3+
delayed init
4+
new foo(b = 2, a = 1)

test/files/run/t6481.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
abstract class foo(a: Int, b: Int) extends scala.DelayedInit {
2+
def delayedInit(x: => Unit) {
3+
println("delayed init");
4+
x
5+
}
6+
}
7+
8+
object Test {
9+
def main(args: Array[String]) {
10+
new foo(1, 2) { println("new foo(1, 2)") }
11+
new foo(b = 2, a = 1) { println("new foo(b = 2, a = 1)") }
12+
}
13+
}

0 commit comments

Comments
 (0)