Skip to content

Commit 7c31ad1

Browse files
committed
Cleanup of implicit modifiers scheme
Implicit modifiers were quite irregular compared to the other ones. This commit does a cleanup.
1 parent 0e954f9 commit 7c31ad1

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
115115

116116
case class Var() extends Mod(Flags.Mutable)
117117

118-
case class Implicit(flag: FlagSet = Flags.ImplicitCommon) extends Mod(flag)
118+
case class Implicit() extends Mod(Flags.ImplicitCommon)
119119

120120
case class Final() extends Mod(Flags.Final)
121121

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ object Comments {
119119
def apply(comment: Comment, code: String, codePos: Position)(implicit ctx: Context) =
120120
new UseCase(comment, code, codePos) {
121121
val untpdCode = {
122-
val tree = new Parser(new SourceFile("<usecase>", code)).localDef(codePos.start, EmptyFlags)
122+
val tree = new Parser(new SourceFile("<usecase>", code)).localDef(codePos.start)
123123

124124
tree match {
125125
case tree: untpd.DefDef =>

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ object Parsers {
10631063
case FOR =>
10641064
forExpr()
10651065
case IMPLICIT =>
1066-
implicitClosure(in.skipToken(), location)
1066+
implicitClosure(in.offset, location, atPos(in.skipToken()) { Mod.Implicit() })
10671067
case _ =>
10681068
expr1Rest(postfixExpr(), location)
10691069
}
@@ -1114,9 +1114,8 @@ object Parsers {
11141114
/** Expr ::= implicit Id `=>' Expr
11151115
* BlockResult ::= implicit Id [`:' InfixType] `=>' Block
11161116
*/
1117-
def implicitClosure(start: Int, location: Location.Value, implicitMod: Option[Mod] = None): Tree = {
1118-
var mods = atPos(start) { Modifiers(Implicit) }
1119-
if (implicitMod.nonEmpty) mods = mods.withAddedMod(implicitMod.get)
1117+
def implicitClosure(start: Int, location: Location.Value, implicitMod: Mod): Tree = {
1118+
val mods = Modifiers(Implicit).withAddedMod(implicitMod)
11201119
val id = termIdent()
11211120
val paramExpr =
11221121
if (location == Location.InBlock && in.token == COLON)
@@ -1485,7 +1484,7 @@ object Parsers {
14851484
private def modOfToken(tok: Int): Mod = tok match {
14861485
case ABSTRACT => Mod.Abstract()
14871486
case FINAL => Mod.Final()
1488-
case IMPLICIT => Mod.Implicit(ImplicitCommon)
1487+
case IMPLICIT => Mod.Implicit()
14891488
case INLINE => Mod.Inline()
14901489
case LAZY => Mod.Lazy()
14911490
case OVERRIDE => Mod.Override()
@@ -1741,7 +1740,7 @@ object Parsers {
17411740
else {
17421741
if (in.token == IMPLICIT) {
17431742
implicitOffset = in.offset
1744-
implicitMod = atPos(in.skipToken()) { Mod.Implicit(Implicit) }
1743+
implicitMod = atPos(in.skipToken()) { Mod.Implicit() }
17451744
}
17461745
commaSeparated(param)
17471746
}
@@ -2214,9 +2213,9 @@ object Parsers {
22142213
stats.toList
22152214
}
22162215

2217-
def localDef(start: Int, implicitFlag: FlagSet, implicitMod: Option[Mod] = None): Tree = {
2218-
var mods = addFlag(defAnnotsMods(localModifierTokens), implicitFlag)
2219-
if (implicitMod.nonEmpty) mods = mods.withAddedMod(implicitMod.get)
2216+
def localDef(start: Int, implicitMod: Option[Mod] = None): Tree = {
2217+
var mods = defAnnotsMods(localModifierTokens)
2218+
for (imod <- implicitMod) mods = (mods | ImplicitCommon).withAddedMod(imod)
22202219
defOrDcl(start, mods)
22212220
}
22222221

@@ -2239,11 +2238,11 @@ object Parsers {
22392238
else if (isDefIntro(localModifierTokens))
22402239
if (in.token == IMPLICIT) {
22412240
val start = in.offset
2242-
val mod = atPos(in.skipToken()) { Mod.Implicit(ImplicitCommon) }
2243-
if (isIdent) stats += implicitClosure(start, Location.InBlock, Some(mod))
2244-
else stats += localDef(start, ImplicitCommon, Some(mod))
2241+
val mod = atPos(in.skipToken()) { Mod.Implicit() }
2242+
if (isIdent) stats += implicitClosure(start, Location.InBlock, mod)
2243+
else stats += localDef(start, Some(mod))
22452244
} else {
2246-
stats += localDef(in.offset, EmptyFlags)
2245+
stats += localDef(in.offset)
22472246
}
22482247
else if (!isStatSep && (in.token != CASE)) {
22492248
exitOnError = mustStartStat

compiler/test/dotty/tools/dotc/parsing/ModifiersParsingTest.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ class ModifiersParsingTest {
140140

141141
source = "def f(implicit a: Int, b: Int) = ???"
142142
println(source.defParam(0).modifiers)
143-
assert(source.defParam(0).modifiers == List(Mod.Implicit(Flags.Implicit)))
144-
assert(source.defParam(1).modifiers == List(Mod.Implicit(Flags.Implicit)))
143+
assert(source.defParam(0).modifiers == List(Mod.Implicit()))
144+
assert(source.defParam(1).modifiers == List(Mod.Implicit()))
145145

146146
source = "def f(x: Int, y: Int)(implicit a: Int, b: Int) = ???"
147147
assert(source.defParam(0, 0).modifiers == List())
148-
assert(source.defParam(1, 0).modifiers == List(Mod.Implicit(Flags.Implicit)))
148+
assert(source.defParam(1, 0).modifiers == List(Mod.Implicit()))
149149
}
150150

151151
@Test def blockDef = {

0 commit comments

Comments
 (0)