Skip to content

Commit

Permalink
Fix parsing of conditional expressions in parentheses
Browse files Browse the repository at this point in the history
We overlooked that the first parenthesized expression might be a tuple.

See https://users.scala-lang.org/t/parsing-conditionals/9888
  • Loading branch information
odersky committed Mar 20, 2024
1 parent 3694d95 commit 767fc35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2192,7 +2192,8 @@ object Parsers {
def condExpr(altToken: Token): Tree =
val t: Tree =
if in.token == LPAREN then
var t: Tree = atSpan(in.offset) { Parens(inParens(exprInParens())) }
var t: Tree = atSpan(in.offset):
makeTupleOrParens(inParensWithCommas(commaSeparated(exprInParens)))
if in.token != altToken then
if toBeContinued(altToken) then
t = inSepRegion(InCond) {
Expand Down
4 changes: 4 additions & 0 deletions tests/pos/if-parse.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import scala.math.Ordering.Implicits.infixOrderingOps

def test =
if (1, 2) < (3, 4) then 1 else 2

0 comments on commit 767fc35

Please sign in to comment.