Skip to content

Commit c93098b

Browse files
authored
Align implementation with spec of soft modifiers (#15961)
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
2 parents 7f2638c + 6ef281a commit c93098b

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

compiler/src/dotty/tools/dotc/parsing/Tokens.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ object Tokens extends TokensCommon {
247247

248248
final val modifierTokensOrCase: TokenSet = modifierTokens | BitSet(CASE)
249249

250-
final val modifierFollowers = modifierTokensOrCase | defIntroTokens
250+
final val modifierFollowers = modifierTokens | defIntroTokens
251251

252252
/** Is token only legal as start of statement (eof also included)? */
253253
final val mustStartStatTokens: TokenSet = defIntroTokens | modifierTokens | BitSet(IMPORT, EXPORT, PACKAGE)
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
21
erased enum Foo6 {} // error: only access modifiers allowed
32

4-
enum Foo10 {
5-
erased case C6() // error: only access modifiers allowed
3+
enum Foo10 { // error: Enumerations must contain at least one case
4+
erased case C6() // error // error
65
}
76

8-
enum Foo11 {
9-
erased case C6 // error: only access modifiers allowed
7+
enum Foo11 { // error: Enumerations must contain at least one case
8+
erased case C6 // error // error
109
}

tests/neg/i5525.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ enum Foo11 {
2929
protected case C9 // ok
3030
}
3131

32-
enum Foo12 {
32+
enum Foo12 { // error: Enumerations must contain at least one case
3333
inline case C10() // error: only access modifiers allowed
3434
}

tests/pos/i15960.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Foo(open: String) {
2+
def bar(n: Int) = n match {
3+
case 0 => open
4+
case _ => throw new IndexOutOfBoundsException()
5+
}
6+
def baz() = open
7+
}
8+
9+

0 commit comments

Comments
 (0)