Skip to content

Commit 2093b87

Browse files
committed
Some parser changes to handle erased as a soft keyword
1 parent 63d31a6 commit 2093b87

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

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

+18-13
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ object Parsers {
190190
def isPureArrow(name: Name): Boolean = isIdent(name) && Feature.pureFunsEnabled
191191
def isPureArrow: Boolean = isPureArrow(nme.PUREARROW) || isPureArrow(nme.PURECTXARROW)
192192
def isErased = isIdent(nme.erased) && in.erasedEnabled
193+
// Are we seeing an `erased` soft keyword that will not be an identifier?
194+
def isErasedKw = isErased && in.isSoftModifierInParamModifierPosition
193195
def isSimpleLiteral =
194196
simpleLiteralTokens.contains(in.token)
195197
|| isIdent(nme.raw.MINUS) && numericLitTokens.contains(in.lookahead.token)
@@ -1545,8 +1547,8 @@ object Parsers {
15451547
else {
15461548
val paramStart = in.offset
15471549
def addErased() =
1548-
erasedArgs.addOne(isErased)
1549-
if isErased then { in.skipToken(); }
1550+
erasedArgs.addOne(isErasedKw)
1551+
if isErasedKw then { in.skipToken(); }
15501552
addErased()
15511553
val ts = in.currentRegion.withCommasExpected {
15521554
funArgType() match
@@ -2379,7 +2381,7 @@ object Parsers {
23792381
*/
23802382
def binding(mods: Modifiers): Tree =
23812383
atSpan(in.offset) {
2382-
val mods1 = if isErased then addModifier(mods) else mods
2384+
val mods1 = if isErasedKw then addModifier(mods) else mods
23832385
makeParameter(bindingName(), typedOpt(), mods1)
23842386
}
23852387

@@ -2578,7 +2580,7 @@ object Parsers {
25782580
else in.currentRegion.withCommasExpected {
25792581
var isFormalParams = false
25802582
def exprOrBinding() =
2581-
if isErased then isFormalParams = true
2583+
if isErasedKw then isFormalParams = true
25822584
if isFormalParams then binding(Modifiers())
25832585
else
25842586
val t = exprInParens()
@@ -3221,7 +3223,7 @@ object Parsers {
32213223
def param(): ValDef = {
32223224
val start = in.offset
32233225
var mods = impliedMods.withAnnotations(annotations())
3224-
if (isErased && in.isSoftModifierInParamModifierPosition)
3226+
if isErasedKw then
32253227
mods = addModifier(mods)
32263228
if (ofClass) {
32273229
mods = addFlag(modifiers(start = mods), ParamAccessor)
@@ -3279,16 +3281,19 @@ object Parsers {
32793281
if prefix && !isIdent(nme.using) && !isIdent(nme.erased) then param() :: Nil
32803282
else
32813283
paramMods()
3282-
val firstParamMod =
3283-
var mods = EmptyModifiers
3284-
if isErased then mods = addModifier(mods)
3285-
mods
32863284
if givenOnly && !impliedMods.is(Given) then
32873285
syntaxError(em"`using` expected")
3288-
val isParams =
3289-
!impliedMods.is(Given)
3290-
|| startParamTokens.contains(in.token)
3291-
|| isIdent && (in.name == nme.inline || in.lookahead.isColon)
3286+
val (firstParamMod, isParams) =
3287+
var mods = EmptyModifiers
3288+
if in.lookahead.isColon then
3289+
(mods, true)
3290+
else
3291+
if isErased then mods = addModifier(mods)
3292+
val isParams =
3293+
!impliedMods.is(Given)
3294+
|| startParamTokens.contains(in.token)
3295+
|| isIdent && (in.name == nme.inline || in.lookahead.isColon)
3296+
(mods, isParams)
32923297
(if isParams then commaSeparated(() => param())
32933298
else contextTypes(ofClass, nparams, impliedMods)) match {
32943299
case Nil => Nil
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def f1(x: Int, erased y: Int) = 0
2+
def f2(x: Int, erased: Int) = 0
3+
inline def f3(x: Int, inline erased: Int) = 0
4+
def f4(x: Int, erased inline: Int) = 0
5+
// inline def f5(x: Int, erased inline y: Int) = 0 // should parse but rejected later
6+
7+
def f6(using erased y: Int) = 0
8+
def f7(using erased: Int) = 0
9+
inline def f8(using inline erased: Int) = 0
10+
def f9(using erased inline: Int) = 0
11+
// inline def f10(using erased inline x: Int) = 0 // should parse but rejected later
12+
def f11(using erased Int) = 0
13+
14+
val v1 = (erased: Int) => 0
15+
val v2: Int => Int = erased => 0
16+
val v3 = (erased x: Int) => 0
17+
val v4: (erased Int) => Int = (erased x) => 0
18+
val v5: (erased: Int) => Int = x => 0

0 commit comments

Comments
 (0)