Skip to content

Commit 1e9068e

Browse files
som-snytttgodzik
authored andcommitted
Prefer chaining, avoid duplication in finally
[Cherry-picked c8131c0]
1 parent b71066a commit 1e9068e

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ object Parsers {
9797
private val InCase: Region => Region = Scanners.InCase(_)
9898
private val InCond: Region => Region = Scanners.InParens(LPAREN, _)
9999
private val InFor : Region => Region = Scanners.InBraces(_)
100-
private val InBrk : Region => Region = _.match
100+
private val InBrk : Region => Region =
101101
case p: Scanners.InParens => Scanners.Indented(p.indentWidth, p.prefix, p)
102102
case r => r
103103

@@ -2132,27 +2132,25 @@ object Parsers {
21322132
def condExpr(altToken: Token): Tree =
21332133
val t: Tree =
21342134
if in.token == LPAREN then
2135-
var t: Tree =
2136-
inSepRegion(InBrk): // allow inferred NEWLINE for observeIndented below
2137-
atSpan(in.offset):
2138-
makeTupleOrParens(inParensWithCommas(commaSeparated(exprInParens)))
2139-
if in.token != altToken then
2140-
if toBeContinued(altToken) then
2141-
t = inSepRegion(InCond) {
2135+
inSepRegion(InBrk): // allow inferred NEWLINE for observeIndented below
2136+
atSpan(in.offset):
2137+
makeTupleOrParens(inParensWithCommas(commaSeparated(exprInParens)))
2138+
.pipe: t =>
2139+
if in.token == altToken then t
2140+
else if toBeContinued(altToken) then
2141+
inSepRegion(InCond):
21422142
expr1Rest(
21432143
postfixExprRest(
21442144
simpleExprRest(t, Location.ElseWhere),
21452145
Location.ElseWhere),
21462146
Location.ElseWhere)
2147-
}
21482147
else
21492148
if rewriteToNewSyntax(t.span) then
2150-
dropParensOrBraces(t.span.start, s"${tokenString(altToken)}")
2149+
dropParensOrBraces(t.span.start, tokenString(altToken))
21512150
in.observeIndented()
21522151
return t
2153-
t
21542152
else if in.isNestedStart then
2155-
try expr() finally newLinesOpt()
2153+
expr().tap(_ => newLinesOpt())
21562154
else
21572155
inSepRegion(InCond)(expr())
21582156
if rewriteToOldSyntax(t.span.startPos) then revertToParens(t)

0 commit comments

Comments
 (0)