Skip to content

Commit

Permalink
bugfix: Show better error when no { is before case
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Sep 4, 2022
1 parent ecc0076 commit 6a10e34
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,9 @@ class ScalametaParser(input: Input)(implicit dialect: Dialect) { parser =>
if (acceptOpt[Indentation.Indent]) {
autoEndPos(t)(Term.Match(t, indentedAfterOpen(caseClauses())))
} else {
autoEndPos(t)(Term.Match(t, inBracesOrNil(caseClauses())))
autoEndPos(t)(
Term.Match(t, inBracesOr(caseClauses(), syntaxErrorExpected[LeftBrace]))
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ class ParseSuite extends TreeSuiteBase with CommonTrees {
): Unit =
checkParsedTree(code, _.entrypointStat(), syntax)(tree)

protected def runTestError[T <: Tree](code: String, expected: String)(
implicit parser: String => T
): Unit = {
val error = intercept[ParseException] {
val result = parser(code)
throw new ParseException(
Position.None,
s"Statement ${code} should not parse! Got result ${result.structure}"
)
}
assert(
error.getMessage.contains(expected),
s"Expected [${error.getMessage}] to contain [${expected}]."
)
}
}

object MoreHelpers {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1397,4 +1397,13 @@ class TermSuite extends ParseSuite {
)
}

test("scala3-syntax") {

runTestError[Term](
"""|() match
| case _: Unit => ()""".stripMargin,
"error: { expected but case found"
)(term(_))

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,4 @@ trait BaseDottySuite extends ParseSuite {
assertLayout.foreach(assertNoDiff(reprintedCode, _, "Reprinted stat"))
}

protected def runTestError[T <: Tree](code: String, expected: String)(
implicit parser: String => T
): Unit = {
val error = intercept[ParseException] {
val result = parser(code)
throw new ParseException(
Position.None,
s"Statement ${code} should not parse! Got result ${result.structure}"
)
}
assert(
error.getMessage.contains(expected),
s"Expected [${error.getMessage}] to contain [${expected}]."
)
}
}

0 comments on commit 6a10e34

Please sign in to comment.