Skip to content

Catch clause always require case on newline #14061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tgodzik opened this issue Dec 7, 2021 · 0 comments · Fixed by #14066
Closed

Catch clause always require case on newline #14061

tgodzik opened this issue Dec 7, 2021 · 0 comments · Fixed by #14066
Assignees
Milestone

Comments

@tgodzik
Copy link
Contributor

tgodzik commented Dec 7, 2021

Compiler version

3.1.0

Minimized code

def main(args: Array[String]): Unit =
  val bar: PartialFunction[Throwable, Unit] =
    case e: IllegalArgumentException => e.printStackTrace
    case e: Throwable => e.printStackTrace
  try
    println("a")
  catch
    bar
  finally
    println("a")

Output

[error] -- [E000] Syntax Error: /home/tgodzik/Documents/workspaces/scala3-example-project/src/main/scala/Main.scala:9:2 
[error] 9 |  catch
[error]   |  ^^^^^
[error]   |  The catch block does not contain a valid expression, try
[error]   |  adding a case like - case e: Exception => to the block

Expectation

Test compiles, according to https://docs.scala-lang.org/scala3/reference/syntax.html#expressions ‘catch’ (Expr | ExprCaseClause) -> catch should be possible to follow by an expression, newline should not cause any issues.

Is this an expected behaviour?

@tgodzik tgodzik changed the title Catch clause always require case Catch clause always require case on newline Dec 7, 2021
@odersky odersky self-assigned this Dec 7, 2021
odersky added a commit to dotty-staging/dotty that referenced this issue Dec 7, 2021
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
@Kordyjan Kordyjan added this to the 3.1.2 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants