Skip to content

Commit 5ec0bdf

Browse files
committed
Postponing desugaring of Try nodes.
Instead of desugaring in parser desugaring is now done during desugaring.
1 parent 8f0271c commit 5ec0bdf

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

Diff for: src/dotty/tools/dotc/ast/Desugar.scala

+10
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,16 @@ object desugar {
817817
case PatDef(mods, pats, tpt, rhs) =>
818818
val pats1 = if (tpt.isEmpty) pats else pats map (Typed(_, tpt))
819819
flatTree(pats1 map (makePatDef(mods, _, rhs)))
820+
case ParsedTry(body, handler, finalizer) =>
821+
handler match {
822+
case Match(EmptyTree, cases) => Try(body, cases, finalizer)
823+
case EmptyTree => Try(body, Nil, finalizer)
824+
case _ =>
825+
Try(body,
826+
List(CaseDef(Ident(nme.DEFAULT_EXCEPTION_NAME), EmptyTree, Apply(handler, Ident(nme.DEFAULT_EXCEPTION_NAME)))),
827+
finalizer)
828+
}
829+
820830
}
821831
}.withPos(tree.pos)
822832

Diff for: src/dotty/tools/dotc/ast/untpd.scala

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
3232
def withName(name: Name)(implicit ctx: Context) = cpy.ModuleDef(this)(mods, name.toTermName, impl)
3333
}
3434

35+
case class ParsedTry(expr: Tree, handler: Tree, finalizer: Tree) extends TermTree
36+
3537
case class SymbolLit(str: String) extends TermTree
3638
case class InterpolatedString(id: TermName, strings: List[Literal], elems: List[Tree]) extends TermTree
3739
case class Function(args: List[Tree], body: Tree) extends Tree {

Diff for: src/dotty/tools/dotc/parsing/Parsers.scala

+1-9
Original file line numberDiff line numberDiff line change
@@ -914,15 +914,7 @@ object Parsers {
914914
val finalizer =
915915
if (handler.isEmpty || in.token == FINALLY) { accept(FINALLY); expr() }
916916
else EmptyTree
917-
handler match {
918-
case Match(sel, cases) => Try(body, cases, finalizer)
919-
case EmptyTree => Try(body, Nil, finalizer)
920-
case _ =>
921-
Try(body,
922-
List(CaseDef(Ident(nme.DEFAULT_EXCEPTION_NAME), EmptyTree, Apply(handler, Ident(nme.DEFAULT_EXCEPTION_NAME)))),
923-
finalizer)
924-
}
925-
917+
ParsedTry(body, handler, finalizer)
926918
}
927919
case THROW =>
928920
atPos(in.skipToken()) { Throw(expr()) }

0 commit comments

Comments
 (0)