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

[Cherry-picked 767fc35]
  • Loading branch information
odersky authored and WojciechMazur committed Jul 3, 2024
1 parent 22a5408 commit 746dbc9
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 @@ -2099,7 +2099,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 746dbc9

Please sign in to comment.