Skip to content

Commit 538b5dd

Browse files
committed
Generalize NewWithArgs
I noted another useless boxing (in Positioned.scala), where we have ``` (new Span(x): Span).coord ``` The allocation should be eliminated but was not.
1 parent d4cd2c0 commit 538b5dd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

compiler/src/dotty/tools/dotc/transform/TreeExtractors.scala

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ object TreeExtractors {
1919
}
2020
}
2121

22-
/** Match new C(args) and extract (C, args) */
22+
/** Match new C(args) and extract (C, args).
23+
* Also admit new C(args): T and {new C(args)}.
24+
*/
2325
object NewWithArgs {
2426
def unapply(t: Tree)(using Context): Option[(Type, List[Tree])] = t match {
2527
case Apply(Select(New(_), nme.CONSTRUCTOR), args) =>
2628
Some((t.tpe, args))
29+
case Typed(expr, _) => unapply(expr)
30+
case Block(Nil, expr) => unapply(expr)
2731
case _ =>
2832
None
2933
}

0 commit comments

Comments
 (0)