Skip to content

Incorrect warning with -no-indent #21749

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
OlegYch opened this issue Oct 10, 2024 · 3 comments · Fixed by #23216
Closed

Incorrect warning with -no-indent #21749

OlegYch opened this issue Oct 10, 2024 · 3 comments · Fixed by #23216

Comments

@OlegYch
Copy link
Contributor

OlegYch commented Oct 10, 2024

Compiler version

3.3-3.5 with -no-indent option

Minimized code

1 match {
  case 1 =>
    case class Test(name: String)
    Nil
}

Output

4 |      Nil
  |      ^
  |      Line is indented too far to the right, or a `{` or `:` is missing

Expectation

no warning

@OlegYch OlegYch added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 10, 2024
@KacperFKorban KacperFKorban added area:parser Spree Suitable for a future Spree and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 13, 2024
@mbovel
Copy link
Member

mbovel commented May 19, 2025

Why is this a bug? It seems expected to me that this is not parsable with -no-indent. Why would the braces around the case body not be required?

@mbovel mbovel removed the Spree Suitable for a future Spree label May 19, 2025
@OlegYch
Copy link
Contributor Author

OlegYch commented May 19, 2025

@mbovel it was always parsable

@mbovel
Copy link
Member

mbovel commented May 21, 2025

@mbovel it was always parsable

You're right! The relevant rules of the syntax summary are

MatchClause       ::=  ‘match’ <<< CaseClauses >>>
CaseClauses       ::=  CaseClause { CaseClause }
CaseClause        ::=  ‘case’ Pattern [Guard] ‘=>’ Block
Block             ::=  {BlockStat semi} [BlockResult]
BlockStat         ::=  Import
                    |  {Annotation {nl}} {LocalModifier} Def
                    |  Extension
                    |  Expr1
                    |  EndMarker
Def               ::=  ‘val’ PatDef
                    |  ‘var’ PatDef
                    |  ‘def’ DefDef
                    |  ‘type’ {nl} TypeDef
                    |  TmplDef
TmplDef           ::=  ([‘case’] ‘class’ | ‘trait’) ClassDef
                    |  [‘case’] ‘object’ ObjectDef
                    |  ‘enum’ EnumDef
                    |  'given' (GivenDef | OldGivenDef)
ClassDef          ::=  id ClassConstr [Template]

According to this, the body of a case can start with one or more Defs without requiring braces or indentation. That comes as a surprise to me.

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