Skip to content
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

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

Open
som-snytt opened this issue Feb 20, 2025 · 2 comments · May be fixed by #22657
Open

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

som-snytt opened this issue Feb 20, 2025 · 2 comments · May be fixed by #22657
Assignees
Labels
area:parser better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug Spree Suitable for a future Spree

Comments

@som-snytt
Copy link
Contributor

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.

@som-snytt som-snytt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 20, 2025
@hamzaremmal hamzaremmal self-assigned this Feb 20, 2025
@Gedochao Gedochao added area:parser and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 21, 2025
@mbovel mbovel added the Spree Suitable for a future Spree label Feb 23, 2025
@mbovel
Copy link
Member

mbovel commented Feb 23, 2025

This issue was picked for the Scala Issue Spree of tomorrow, Monday, February 24th. @hamzaremmal, @ajafri2001 and @Zeleph25 will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here.

@dwijnand
Copy link
Member

A minimisation that includes the cascade errors (comment in and out the print to see the difference):

import CheckUnused.*

class CheckUnused(phaseMode: PhaseMode):
  def resolveUsage: Unit =
    private def cmp(p: Int, q: Int): Boolean =
      false
    print("")
  end resolveUsage
end CheckUnused

object CheckUnused:
  enum PhaseMode:
    case Aggregate
    case Report
end CheckUnused

@hamzaremmal hamzaremmal linked a pull request Feb 24, 2025 that will close this issue
3 tasks
@hamzaremmal hamzaremmal added the better-errors Issues concerned with improving confusing/unhelpful diagnostic messages label Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:parser better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug Spree Suitable for a future Spree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants