Skip to content

Self-type indentation is unexpectedly significant #9515

Closed
@som-snytt

Description

@som-snytt

Minimized code

trait C {
self =>

  class D

  class E
}

Output

-- Warning: badindent.scala:9:2 ------------------------------------------------
9 |  class E
  |  ^
  |  Line is indented too far to the right, or a `{` or `:` is missing
1 warning found

IRL, source had a few indentation quirks, so it can be tricky-to-impossible to locate the offender 800 lines back.

[info] Compiling 61 Scala sources to .../target/scala-0.26/classes ...
[warn] -- Warning: .../src/main/scala/scala/collection/parallel/ParIterableLike.scala:888:2 
[warn] 888 |  protected[this] abstract class Composite[FR, SR, R, First <: StrictSplitterCheckTask[FR, _], Second <: StrictSplitterCheckTask[SR, _]]
[warn]     |  ^
[warn]     |  Line is indented too far to the right, or a `{` or `:` is missing

Expectation

The problem is the indentation of the self type.

It is not obvious whether the indentation of the self type should matter.

The warning should tell me why it thinks my indentation is wrong, i.e., which previous line established the expected indentation.

The warning is due to the template class D checking the indentation of the following line, which is class E.

Maybe the extra help, e.g., mentioning is misaligned with line 3, should be enabled under a flag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions