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

open is not treated as a normal identifier inside match #15960

Closed
andrelfpinto opened this issue Sep 4, 2022 · 1 comment · Fixed by #15961
Closed

open is not treated as a normal identifier inside match #15960

andrelfpinto opened this issue Sep 4, 2022 · 1 comment · Fixed by #15961

Comments

@andrelfpinto
Copy link

Compiler version

3.1.3

Minimized code

class Foo(open: String) {
  def bar(n: Int) = n match {
    case 0 => open
    case _ => throw new IndexOutOfBoundsException()
  }
  def baz() = open
}

Output

-- [E088] Syntax Error: Open.scala:4:4 ----------------------------------------------------
4 |    case _ => throw new IndexOutOfBoundsException()
  |    ^^^^
  |    Expected start of definition

Explanation
===========
You have to provide either class, trait, object, or enum definitions after qualifiers

1 error found

Expectation

bar should compile as baz does.

According to this:

open is a soft modifier. It is treated as a normal identifier unless it is in modifier position.

It seems like open is not being treated as a normal identifier inside match.

@andrelfpinto andrelfpinto added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 4, 2022
@som-snytt
Copy link
Contributor

It needs to work a bit harder to disambiguate case.

class Foo(open: String):
  def bar(n: Int) = n match
    case 0 => open case class C(); ???
    case 1 => case class K(); ???
    case _ => throw new IndexOutOfBoundsException()
  def baz() = { open class D; () }

It says

Modifier open is redundant for this definition

but not illegal.

odersky added a commit to dotty-staging/dotty that referenced this issue Sep 4, 2022
The spec in https://dotty.epfl.ch/docs/reference/soft-modifier.html says:

> A soft modifier is treated as potential modifier of a definition if it is followed by a hard modifier or a keyword combination starting a definition (def, val, var, type, given, class, trait, object, enum, case class, case object). Between the two words there may be a sequence of newline tokens and soft modifiers.

But the implementation recognized also soft modifiers in front of just `case`, not followed by `class` or `object`.
The change caused some breakage for enum cases, where we have `case` alone, but that one cannot be preceded by any
soft modifiers anyway. So only neg tests were affected.

Fixes scala#15960
@KacperFKorban KacperFKorban added area:parser and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 4, 2022
odersky added a commit that referenced this issue Sep 5, 2022
The spec in https://dotty.epfl.ch/docs/reference/soft-modifier.html says:

> A soft modifier is treated as potential modifier of a definition if it is followed by a hard modifier or a keyword combination starting a definition (def, val, var, type, given, class, trait, object, enum, case class, case object). Between the two words there may be a sequence of newline tokens and soft modifiers.

But the implementation recognized also soft modifiers in front of just `case`, not followed by `class` or `object`.
The change caused some breakage for enum cases, where we have `case` alone, but that one cannot be preceded by any
soft modifiers anyway. So only neg tests were affected.

Fixes #15960
mpollmeier pushed a commit to mpollmeier/dotty that referenced this issue Oct 16, 2022
The spec in https://dotty.epfl.ch/docs/reference/soft-modifier.html says:

> A soft modifier is treated as potential modifier of a definition if it is followed by a hard modifier or a keyword combination starting a definition (def, val, var, type, given, class, trait, object, enum, case class, case object). Between the two words there may be a sequence of newline tokens and soft modifiers.

But the implementation recognized also soft modifiers in front of just `case`, not followed by `class` or `object`.
The change caused some breakage for enum cases, where we have `case` alone, but that one cannot be preceded by any
soft modifiers anyway. So only neg tests were affected.

Fixes scala#15960
@Kordyjan Kordyjan added this to the 3.2.2 milestone Aug 1, 2023
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.

4 participants