Skip to content

Commit

Permalink
bugfix: Show better error when no { is before case (#2830)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Sep 4, 2022
1 parent 69fa613 commit 646e962
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,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,6 +1397,16 @@ class TermSuite extends ParseSuite {
)
}

test("scala3-syntax") {

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

}

test("using") {
assertTerm("Set(using)") {
Term.Apply(Term.Name("Set"), List(Term.Name("using")))
Expand Down
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 646e962

Please sign in to comment.