Skip to content

Missing case body indent errors at missing unindent #22772

Open
@som-snytt

Description

@som-snytt

Compiler version

3.6.4

Minimized code

def f(i: Int) =
  i match
  case 42 =>
  i + 1
  case 27 =>
//^^^^
//unindent expected, but 'case' found
  i - 1
  case _ =>
  i

Output

-- [E040] Syntax Error: /home/amarki/snips/bad-case-align.scala:6:2 ------------
6 |  case 27 =>
  |  ^^^^
  |  unindent expected, but 'case' found
-- [E103] Syntax Error: /home/amarki/snips/bad-case-align.scala:8:2 ------------
8 |  case _ =>
  |  ^^^^
  |  Illegal start of toplevel definition
  |
  | longer explanation available when compiling with `-explain`
2 errors found
Compilation failed

Expectation

This is one of those little parse error behaviors that could be improved:

unindent expected means indent expected but previously missing.

This is } expected but for indents.

As usual, the deficiency is that I have to scan backward to figure out my typo. That is a bit harder with braceless syntax. (I might be unaware of when an indent is required.) Another well known use case is that while cut/pasting code, I often lose formatting and get it wrong.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions