Skip to content

Commit 0ea0eba

Browse files
authored
Fix parsing of conditional expressions in parentheses (#19985)
We overlooked that the first parenthesized expression might be a tuple. See https://users.scala-lang.org/t/parsing-conditionals/9888
2 parents 4554131 + 767fc35 commit 0ea0eba

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -2192,7 +2192,8 @@ object Parsers {
21922192
def condExpr(altToken: Token): Tree =
21932193
val t: Tree =
21942194
if in.token == LPAREN then
2195-
var t: Tree = atSpan(in.offset) { Parens(inParens(exprInParens())) }
2195+
var t: Tree = atSpan(in.offset):
2196+
makeTupleOrParens(inParensWithCommas(commaSeparated(exprInParens)))
21962197
if in.token != altToken then
21972198
if toBeContinued(altToken) then
21982199
t = inSepRegion(InCond) {

tests/pos/if-parse.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import scala.math.Ordering.Implicits.infixOrderingOps
2+
3+
def test =
4+
if (1, 2) < (3, 4) then 1 else 2

0 commit comments

Comments
 (0)