Skip to content

Weaken failing assertion in Scanner #12613

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

Merged
merged 1 commit into from
May 31, 2021
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented May 26, 2021

Fixes #12605

@som-snytt
Copy link
Contributor

Just to document, REPL is OK with the fix.

scala> def f =
     |   List((2, 3)).filter case (a, b) => b > a
2 |  List((2, 3)).filter case (a, b) => b > a
  |                      ^^^^
  |                      unindent expected, but 'case' found

scala> def f =
     | List((2, 3)).filter case (a, b) => b > a
2 |List((2, 3)).filter case (a, b) => b > a
  |                    ^^^^
  |                    eof expected, but 'case' found

I was curious that scalac follows up a syntax error with a type error, instead of halting earlier.

-- [E040] Syntax Error: i12605.scala:4:24 ----------------------------------------------------------------------------
4 |    List((2, 3)).filter case (a, b) => b > a
  |                        ^^^^
  |                        unindent expected, but 'case' found
-- [E040] Syntax Error: i12605.scala:10:0 ----------------------------------------------------------------------------
10 |
   |^
   |'}' expected, but eof found
-- [E007] Type Mismatch Error: i12605.scala:4:4 ----------------------------------------------------------------------
4 |    List((2, 3)).filter case (a, b) => b > a
  |    ^^^^^^^^^^^^^^^^^^^
  |    Found:    (((Int, Int)) => Boolean) => List[(Int, Int)]
  |    Required: List[(Int, Int)]

More opinionated messaging might help the user trying to remember if braceless syntax like for one-line catch applies here; I'm still not sure why there is no one-line match. Possibly "Big problem" never happens; it happens with case because of lookahead for case class, interacting with case in block.

    def observeOutdented(): Unit = currentRegion match
      case r: Indented if !r.isOutermost && closingRegionTokens.contains(token) =>
        if !(token == CASE && r.prefix == MATCH) then
          if next.token == EMPTY then
            currentRegion = r.enclosing
            insert(OUTDENT, offset)
          else if token == CASE then error("That case is messed up")
          else error("Big problem with lookahead trying to insert outdent")
      case _ =>

Copy link
Member

@bishabosha bishabosha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bishabosha bishabosha merged commit 88a5779 into scala:master May 31, 2021
@bishabosha bishabosha deleted the fix-12605 branch May 31, 2021 16:31
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler prints stacktrace on syntax error involving case and missing parens
4 participants