Skip to content

Commit b84078d

Browse files
committed
Make erased a soft modifier
Make erased a soft modifier, valid always (not conditional under -Yerased-terms)
1 parent 9247e72 commit b84078d

File tree

6 files changed

+19
-22
lines changed

6 files changed

+19
-22
lines changed

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ object StdNames {
456456
val equalsNumNum : N = "equalsNumNum"
457457
val equalsNumObject : N = "equalsNumObject"
458458
val equals_ : N = "equals"
459+
val erased: N = "erased"
459460
val error: N = "error"
460461
val eval: N = "eval"
461462
val eqlAny: N = "eqlAny"

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ object Parsers {
13661366
}
13671367
else {
13681368
openParens.change(LPAREN, 1)
1369-
imods = modifiers(funTypeArgMods)
1369+
if isIdent(nme.erased) then imods = addModifier(imods)
13701370
val paramStart = in.offset
13711371
val ts = funArgType() match {
13721372
case Ident(name) if name != tpnme.WILDCARD && in.token == COLON =>
@@ -1853,7 +1853,7 @@ object Parsers {
18531853
def isSpecialClosureStart =
18541854
val lookahead = in.LookaheadScanner()
18551855
lookahead.nextToken()
1856-
lookahead.isIdent(nme.using) || lookahead.token == ERASED
1856+
lookahead.isIdent(nme.using) || lookahead.isIdent(nme.erased)
18571857
if in.token == IMPLICIT then
18581858
closure(start, location, modifiers(BitSet(IMPLICIT)))
18591859
else if in.token == LPAREN && isSpecialClosureStart then
@@ -2080,7 +2080,7 @@ object Parsers {
20802080
var mods1 = mods
20812081
if mods.flags.isEmpty then
20822082
if isIdent(nme.using) then mods1 = addMod(mods1, atSpan(in.skipToken()) { Mod.Given() })
2083-
if in.token == ERASED then mods1 = addModifier(mods1)
2083+
if isIdent(nme.erased) then mods1 = addModifier(mods1)
20842084
try
20852085
commaSeparated(() => binding(mods1))
20862086
finally
@@ -2681,14 +2681,14 @@ object Parsers {
26812681
case FINAL => Mod.Final()
26822682
case IMPLICIT => Mod.Implicit()
26832683
case GIVEN => Mod.Given()
2684-
case ERASED => Mod.Erased()
26852684
case LAZY => Mod.Lazy()
26862685
case OVERRIDE => Mod.Override()
26872686
case PRIVATE => Mod.Private()
26882687
case PROTECTED => Mod.Protected()
26892688
case SEALED => Mod.Sealed()
26902689
case IDENTIFIER =>
26912690
name match {
2691+
case nme.erased => Mod.Erased()
26922692
case nme.inline => Mod.Inline()
26932693
case nme.opaque => Mod.Opaque()
26942694
case nme.open => Mod.Open()
@@ -2769,8 +2769,6 @@ object Parsers {
27692769
normalize(loop(start))
27702770
}
27712771

2772-
val funTypeArgMods: BitSet = BitSet(ERASED)
2773-
27742772
/** Wrap annotation or constructor in New(...).<init> */
27752773
def wrapNew(tpt: Tree): Select = Select(New(tpt), nme.CONSTRUCTOR)
27762774

@@ -2896,7 +2894,7 @@ object Parsers {
28962894
if in.token == IMPLICIT then addParamMod(() => Mod.Implicit())
28972895
else
28982896
if isIdent(nme.using) then addParamMod(() => Mod.Given())
2899-
if in.token == ERASED then addParamMod(() => Mod.Erased())
2897+
if isIdent(nme.erased) then addParamMod(() => Mod.Erased())
29002898

29012899
def param(): ValDef = {
29022900
val start = in.offset

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ object Scanners {
232232
private val commentBuf = Cbuf()
233233

234234
private def handleMigration(keyword: Token): Token =
235-
if (keyword == ERASED && !ctx.settings.YerasedTerms.value) IDENTIFIER
236-
else if (!isScala2CompatMode) keyword
235+
if (!isScala2CompatMode) keyword
237236
else if (scala3keywords.contains(keyword)) treatAsIdent()
238237
else keyword
239238

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ abstract class TokensCommon {
9595
//final val THEN = 60; enter(THEN, "then")
9696
//final val FORSOME = 61; enter(FORSOME, "forSome") // TODO: deprecate
9797
//final val ENUM = 62; enter(ENUM, "enum")
98-
//final val ERASED = 63; enter(ERASED, "erased")
9998

10099
/** special symbols */
101100
final val COMMA = 70; enter(COMMA, "','")
@@ -181,10 +180,9 @@ object Tokens extends TokensCommon {
181180
final val THEN = 60; enter(THEN, "then")
182181
final val FORSOME = 61; enter(FORSOME, "forSome") // TODO: deprecate
183182
final val ENUM = 62; enter(ENUM, "enum")
184-
final val ERASED = 63; enter(ERASED, "erased")
185-
final val GIVEN = 64; enter(GIVEN, "given")
186-
final val EXPORT = 65; enter(EXPORT, "export")
187-
final val MACRO = 66; enter(MACRO, "macro") // TODO: remove
183+
final val GIVEN = 63; enter(GIVEN, "given")
184+
final val EXPORT = 64; enter(EXPORT, "export")
185+
final val MACRO = 65; enter(MACRO, "macro") // TODO: remove
188186

189187
/** special symbols */
190188
final val NEWLINE = 78; enter(NEWLINE, "end of statement", "new line")
@@ -236,7 +234,7 @@ object Tokens extends TokensCommon {
236234
final val defIntroTokens: TokenSet = templateIntroTokens | dclIntroTokens
237235

238236
final val localModifierTokens: TokenSet = BitSet(
239-
ABSTRACT, FINAL, SEALED, IMPLICIT, LAZY, ERASED)
237+
ABSTRACT, FINAL, SEALED, IMPLICIT, LAZY)
240238

241239
final val accessModifierTokens: TokenSet = BitSet(
242240
PRIVATE, PROTECTED)
@@ -280,7 +278,7 @@ object Tokens extends TokensCommon {
280278
*/
281279
final val startParamTokens: BitSet = modifierTokens | BitSet(VAL, VAR, AT)
282280

283-
final val scala3keywords = BitSet(ENUM, ERASED, GIVEN)
281+
final val scala3keywords = BitSet(ENUM, GIVEN)
284282

285-
final val softModifierNames = Set(nme.inline, nme.opaque, nme.open)
283+
final val softModifierNames = Set(nme.erased, nme.inline, nme.opaque, nme.open)
286284
}

docs/docs/internals/syntax.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ yield
104104
### Soft keywords
105105

106106
```
107-
as derives extension inline on opaque open using
107+
as derives erased extension inline on opaque open
108+
using
108109
* + -
109110
```
110111

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22
erased enum Foo6 {} // error: only access modifiers allowed
33

4-
enum Foo10 {
5-
erased case C6() // error: only access modifiers allowed
4+
enum Foo10 { // error
5+
erased case C6() // error: only access modifiers allowed // error // error
66
}
77

8-
enum Foo11 {
9-
erased case C6 // error: only access modifiers allowed
8+
enum Foo11 { // error
9+
erased case C6 // error: only access modifiers allowed // error // error
1010
}

0 commit comments

Comments
 (0)