Skip to content

Commit e94bed3

Browse files
committed
Make is type safe
This is achieved by creating a new opaque type `Flag` that represents a single flag.
1 parent e6da30e commit e94bed3

File tree

7 files changed

+167
-150
lines changed

7 files changed

+167
-150
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
659659
def isExpanded: Boolean = sym.name.is(ExpandedName)
660660
def isAnonymousFunction: Boolean = toDenot(sym).isAnonymousFunction
661661
def isMethod: Boolean = sym.is(Flags.Method)
662-
def isPublic: Boolean = !sym.flags.is(Flags.Private | Flags.Protected)
662+
def isPublic: Boolean = !sym.flags.isOneOf(Flags.Private | Flags.Protected)
663663
def isSynthetic: Boolean = sym.is(Flags.Synthetic)
664664
def isPackageClass: Boolean = sym.is(Flags.PackageClass)
665665
def isModuleClass: Boolean = sym.is(Flags.ModuleClass)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,9 +1016,9 @@ object desugar {
10161016
case tree: MemberDef =>
10171017
var tested: MemberDef = tree
10181018
def fail(msg: String) = ctx.error(msg, tree.sourcePos)
1019-
def checkApplicable(flag: FlagSet, test: MemberDefTest): Unit =
1019+
def checkApplicable(flag: Flag, test: MemberDefTest): Unit =
10201020
if (tested.mods.is(flag) && !test.applyOrElse(tree, (md: MemberDef) => false)) {
1021-
fail(i"modifier `$flag` is not allowed for this definition")
1021+
fail(i"modifier `${flag.flagsString}` is not allowed for this definition")
10221022
tested = tested.withMods(tested.mods.withoutFlags(flag))
10231023
}
10241024
checkApplicable(Opaque, legalOpaque)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
183183
annotations: List[Tree] = Nil,
184184
mods: List[Mod] = Nil) {
185185

186-
def is(fs: FlagSet): Boolean = flags.is(fs)
187-
def is(fs: FlagSet, butNot: FlagSet): Boolean = flags.is(fs, butNot = butNot)
186+
def is(flag: Flag): Boolean = flags.is(flag)
187+
def is(flag: Flag, butNot: FlagSet): Boolean = flags.is(flag, butNot = butNot)
188188
def isOneOf(fs: FlagSet): Boolean = flags.isOneOf(fs)
189189
def isOneOf(fs: FlagSet, butNot: FlagSet): Boolean = flags.isOneOf(fs, butNot = butNot)
190190
def isAllOf(fc: FlagSet): Boolean = flags.isAllOf(fc)
@@ -201,8 +201,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
201201
else copy(flags = flags)
202202

203203
def withoutFlags(flags: FlagSet): Modifiers =
204-
if (this.is(flags))
205-
Modifiers(this.flags &~ flags, this.privateWithin, this.annotations, this.mods.filterNot(_.flags.is(flags)))
204+
if (this.isOneOf(flags))
205+
Modifiers(this.flags &~ flags, this.privateWithin, this.annotations, this.mods.filterNot(_.flags.isOneOf(flags)))
206206
else this
207207

208208
def withAddedMod(mod: Mod): Modifiers =

0 commit comments

Comments
 (0)