Skip to content

Commit a041a4c

Browse files
committed
Disallow opaque as a local modifier
1 parent 3c591ed commit a041a4c

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ object Parsers {
201201
canStartExpressionTokens.contains(in.token) &&
202202
!in.isSoftModifierInModifierPosition
203203

204-
def isDefIntro(allowedMods: BitSet): Boolean =
204+
def isDefIntro(allowedMods: BitSet, excludedSoftModifiers: Set[TermName] = Set.empty): Boolean =
205205
in.token == AT ||
206206
(defIntroTokens `contains` in.token) ||
207207
(allowedMods `contains` in.token) ||
208-
in.isSoftModifierInModifierPosition
208+
in.isSoftModifierInModifierPosition && !excludedSoftModifiers.contains(in.name)
209209

210210
def isStatSep: Boolean =
211211
in.token == NEWLINE || in.token == NEWLINES || in.token == SEMI
@@ -3081,7 +3081,7 @@ object Parsers {
30813081
stats += implicitClosure(in.offset, Location.InBlock, modifiers(closureMods))
30823082
else if (isExprIntro)
30833083
stats += expr(Location.InBlock)
3084-
else if (isDefIntro(localModifierTokens))
3084+
else if (isDefIntro(localModifierTokens, excludedSoftModifiers = Set(nme.`opaque`)))
30853085
if (closureMods.contains(in.token)) {
30863086
val start = in.offset
30873087
var imods = modifiers(closureMods)

docs/docs/internals/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,12 @@ Binding ::= (id | ‘_’) [‘:’ Type]
324324
Modifier ::= LocalModifier
325325
| AccessModifier
326326
| ‘override’
327+
| ‘opaque’
327328
LocalModifier ::= ‘abstract’
328329
| ‘final’
329330
| ‘sealed’
330331
| ‘implicit’
331332
| ‘lazy’
332-
| ‘opaque’
333333
| ‘inline’
334334
| ‘erased’
335335
AccessModifier ::= (‘private’ | ‘protected’) [AccessQualifier]

tests/neg/opaque.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ object opaquetypes {
1818
val s: O = "" // should be OK
1919
}
2020

21+
def foo() = {
22+
opaque type X = Int // error
23+
}
24+
2125
}
2226

2327
object logs {

tests/pos/i6287.scala

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
object O{
2-
def m() = {
3-
opaque type T = Int
4-
object T
5-
}
6-
}
71
object A {
8-
{
92
opaque type T = Int
103
object T
114
println
12-
}
135
}

0 commit comments

Comments
 (0)