Skip to content

Commit 2ef00e1

Browse files
committed
Simplify Parser
`implicitOffset` can now be dropped, replaced by manipulating `impliedMods` directly.
1 parent 4f32c24 commit 2ef00e1

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ object Parsers {
8181
* to position spanning from `start` to last read offset, with given point.
8282
* If the last offset is less than or equal to start, the tree `t` did not
8383
* consume any source for its construction. In this case, don't position it yet,
84-
* but wait for its position to be determined by `setChildPositions` when the
84+
* but wait for its position to be determined by `setChildSpans` when the
8585
* parent node is positioned.
8686
*/
8787
def atPos[T <: Positioned](start: Offset, point: Offset)(t: T): T =
@@ -1975,9 +1975,9 @@ object Parsers {
19751975
prefix: Boolean = false, // clause precedes name of an extension method
19761976
firstClause: Boolean = false) // clause is the first in regular list of clauses
19771977
: List[ValDef] = {
1978-
var implicitOffset = -1 // use once
1978+
var impliedMods: Modifiers = EmptyModifiers
19791979

1980-
def param(impliedMods: Modifiers): ValDef = {
1980+
def param(): ValDef = {
19811981
val start = in.offset
19821982
var mods = impliedMods.withAnnotations(annotations())
19831983
if (ofClass) {
@@ -2012,9 +2012,8 @@ object Parsers {
20122012
val default =
20132013
if (in.token == EQUALS) { in.nextToken(); expr() }
20142014
else EmptyTree
2015-
if (implicitOffset >= 0) {
2016-
//mods = mods.withPos(mods.span.union(Span(implicitOffset, implicitOffset)))
2017-
implicitOffset = -1
2015+
if (impliedMods.mods.nonEmpty) {
2016+
impliedMods = impliedMods.withMods(Nil) // keep only flags, so that parameter positions don't overlap
20182017
}
20192018
ValDef(name, tpt, default).withMods(mods)
20202019
}
@@ -2037,18 +2036,16 @@ object Parsers {
20372036
if (in.token == RPAREN && !prefix) Nil
20382037
else {
20392038
def funArgMods(mods: Modifiers): Modifiers =
2040-
if (in.token == IMPLICIT) {
2041-
implicitOffset = in.offset
2039+
if (in.token == IMPLICIT)
20422040
funArgMods(addMod(mods, atPos(accept(IMPLICIT)) { Mod.Implicit() }))
2043-
}
20442041
else if (in.token == ERASED)
20452042
funArgMods(addMod(mods, atPos(accept(ERASED)) { Mod.Erased() }))
20462043
else mods
20472044

2048-
val paramMods = funArgMods(EmptyModifiers)
2045+
impliedMods = funArgMods(EmptyModifiers)
20492046
val clause =
2050-
if (prefix) param(paramMods) :: Nil
2051-
else commaSeparated(() => param(paramMods))
2047+
if (prefix) param() :: Nil
2048+
else commaSeparated(() => param())
20522049
checkVarArgsRules(clause)
20532050
clause
20542051
}

0 commit comments

Comments
 (0)