Skip to content

No graceful recovery from misplaced private modifier in local scope #22631

Open
@som-snytt

Description

@som-snytt

Compiler version

3.6.3

Minimized code

def f: Unit =
  private def cmp ...  // cut/paste error

Output

[error] 274 |    private def cmp(p: Type, q: Type)(using Context): Boolean =
[error]     |    ^^^^^^^
[error]     |    this kind of statement is not allowed here

followed by dozens of diagnostics.

Showing that it blows past the end of the enclosing method at 400, then the next end marker for the class; then errors cascade from outside the local scope.

[error] 274 |    private def cmp(p: Type, q: Type)(using Context): Boolean =
[error]     |    ^^^^^^^
[error]     |    this kind of statement is not allowed here
[error]     |
[error]     | longer explanation available when compiling with `-explain`
[error] -- Error: .../CheckUnused.scala:400:2
[error] 400 |  end resolveUsage
[error]     |  ^^^^^^^^^^^^^^^^
[error]     |  misaligned end marker
[error] -- [E040] Syntax Error: .../CheckUnused.scala:401:0
[error] 401 |end CheckUnused
[error]     |^^^
[error]     |eof expected, but unindent found
[error] -- [E006] Not Found Error: .../CheckUnused.scala:34:38
[error] 34 |class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPhase:
[error]    |                                      ^^^^^^^^^
[error]    |                                      Not found: type PhaseMode
[error]    |

Expectation

Skipping a misplaced modifier seems like an easy recovery strategy.

Skipping just the (correctly indented) bad local def would help.

Correctly stopping at the (correctly aligned) end marker of the enclosing def would help.

Metadata

Metadata

Assignees

Labels

SpreeSuitable for a future Spreearea:parserbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesitype:bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions