Skip to content

Commit 971dacf

Browse files
committed
Prefer chaining, avoid duplication in finally
1 parent 1564f74 commit 971dacf

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

+10-12
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ object Parsers {
105105
private val InCase: Region => Region = Scanners.InCase(_)
106106
private val InCond: Region => Region = Scanners.InParens(LPAREN, _)
107107
private val InFor : Region => Region = Scanners.InBraces(_)
108-
private val InBrk : Region => Region = _.match
108+
private val InBrk : Region => Region =
109109
case p: Scanners.InParens => Scanners.Indented(p.indentWidth, p.prefix, p)
110110
case r => r
111111

@@ -2328,27 +2328,25 @@ object Parsers {
23282328
def condExpr(altToken: Token): Tree =
23292329
val t: Tree =
23302330
if in.token == LPAREN then
2331-
var t: Tree =
2332-
inSepRegion(InBrk): // allow inferred NEWLINE for observeIndented below
2333-
atSpan(in.offset):
2334-
makeTupleOrParens(inParensWithCommas(commaSeparated(exprInParens)))
2335-
if in.token != altToken then
2336-
if toBeContinued(altToken) then
2337-
t = inSepRegion(InCond) {
2331+
inSepRegion(InBrk): // allow inferred NEWLINE for observeIndented below
2332+
atSpan(in.offset):
2333+
makeTupleOrParens(inParensWithCommas(commaSeparated(exprInParens)))
2334+
.pipe: t =>
2335+
if in.token == altToken then t
2336+
else if toBeContinued(altToken) then
2337+
inSepRegion(InCond):
23382338
expr1Rest(
23392339
postfixExprRest(
23402340
simpleExprRest(t, Location.ElseWhere),
23412341
Location.ElseWhere),
23422342
Location.ElseWhere)
2343-
}
23442343
else
23452344
if rewriteToNewSyntax(t.span) then
2346-
dropParensOrBraces(t.span.start, s"${tokenString(altToken)}")
2345+
dropParensOrBraces(t.span.start, tokenString(altToken))
23472346
in.observeIndented()
23482347
return t
2349-
t
23502348
else if in.isNestedStart then
2351-
try expr() finally newLinesOpt()
2349+
expr().tap(_ => newLinesOpt())
23522350
else
23532351
inSepRegion(InCond)(expr())
23542352
if rewriteToOldSyntax(t.span.startPos) then revertToParens(t)

0 commit comments

Comments
 (0)