Skip to content

Commit 02a5955

Browse files
committed
Add language import for erasedTerms
1 parent f38effc commit 02a5955

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

compiler/src/dotty/tools/dotc/config/Feature.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ object Feature:
2424
private val macros = experimental("macros")
2525

2626
val dependent = experimental("dependent")
27+
val erasedTerms = experimental("erasedTerms")
2728
val symbolLiterals: TermName = deprecated("symbolLiterals")
2829

2930
/** Is `feature` enabled by by a command-line setting? The enabling setting is

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ object StdNames {
466466
val equalsNumNum : N = "equalsNumNum"
467467
val equalsNumObject : N = "equalsNumObject"
468468
val equals_ : N = "equals"
469+
val erased: N = "erased"
469470
val error: N = "error"
470471
val eval: N = "eval"
471472
val eqlAny: N = "eqlAny"

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ object Parsers {
230230
else (staged & StageKind.Quoted) != 0
231231
}
232232

233+
extension (td: TokenData = in)
234+
def isErased: Boolean =
235+
td.token == ERASED
236+
|| td.isIdent(nme.erased) && featureEnabled(Feature.erasedTerms)
237+
233238
/* ------------- ERROR HANDLING ------------------------------------------- */
234239

235240
/** The offset of the last time when a statement on a new line was definitely
@@ -1377,7 +1382,7 @@ object Parsers {
13771382
functionRest(Nil)
13781383
}
13791384
else {
1380-
imods = modifiers(funTypeArgMods)
1385+
if in.isErased then imods = addModifier(imods)
13811386
val paramStart = in.offset
13821387
val ts = funArgType() match {
13831388
case Ident(name) if name != tpnme.WILDCARD && in.token == COLON =>
@@ -1864,7 +1869,7 @@ object Parsers {
18641869

18651870
def expr(location: Location): Tree = {
18661871
val start = in.offset
1867-
def isSpecialClosureStart = in.lookahead.token == ERASED
1872+
def isSpecialClosureStart = in.lookahead.isErased
18681873
if in.token == IMPLICIT then
18691874
closure(start, location, modifiers(BitSet(IMPLICIT)))
18701875
else if in.token == LPAREN && isSpecialClosureStart then
@@ -2096,7 +2101,7 @@ object Parsers {
20962101
Nil
20972102
else
20982103
var mods1 = mods
2099-
if in.token == ERASED then mods1 = addModifier(mods1)
2104+
if in.isErased then mods1 = addModifier(mods1)
21002105
try
21012106
commaSeparated(() => binding(mods1))
21022107
finally
@@ -2695,6 +2700,7 @@ object Parsers {
26952700
case SEALED => Mod.Sealed()
26962701
case IDENTIFIER =>
26972702
name match {
2703+
case nme.erased if featureEnabled(Feature.erasedTerms) => Mod.Erased()
26982704
case nme.inline => Mod.Inline()
26992705
case nme.opaque => Mod.Opaque()
27002706
case nme.open => Mod.Open()
@@ -2778,8 +2784,6 @@ object Parsers {
27782784
normalize(loop(start))
27792785
}
27802786

2781-
val funTypeArgMods: BitSet = BitSet(ERASED)
2782-
27832787
/** Wrap annotation or constructor in New(...).<init> */
27842788
def wrapNew(tpt: Tree): Select = Select(New(tpt), nme.CONSTRUCTOR)
27852789

@@ -2902,10 +2906,13 @@ object Parsers {
29022906
def addParamMod(mod: () => Mod) = impliedMods = addMod(impliedMods, atSpan(in.skipToken()) { mod() })
29032907

29042908
def paramMods() =
2905-
if in.token == IMPLICIT then addParamMod(() => Mod.Implicit())
2909+
if in.token == IMPLICIT then
2910+
addParamMod(() => Mod.Implicit())
29062911
else
2907-
if isIdent(nme.using) then addParamMod(() => Mod.Given())
2908-
if in.token == ERASED then addParamMod(() => Mod.Erased())
2912+
if isIdent(nme.using) then
2913+
addParamMod(() => Mod.Given())
2914+
if in.isErased then
2915+
addParamMod(() => Mod.Erased())
29092916

29102917
def param(): ValDef = {
29112918
val start = in.offset

library/src/scala/runtime/stdLibPatches/language.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ object language:
3636
* @see [[https://dotty.epfl.ch/docs/reference/changed-features/numeric-literals]]
3737
*/
3838
object genericNumberLiterals
39+
40+
/** Experimental support for `erased` modifier */
41+
object erasedTerms
42+
3943
end experimental
4044

4145
/** The deprecated object contains features that are no longer officially suypported in Scala.

0 commit comments

Comments
 (0)