Skip to content

Commit d5ed6f5

Browse files
committed
More modifier lock down in Symbols.
1 parent 63e309c commit d5ed6f5

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ trait Symbols { this: Context =>
2121

2222
// ---- Fundamental symbol creation methods ----------------------------------
2323

24-
def newLazySymbol[N <: Name](owner: Symbol, name: N, initFlags: FlagSet, completer: SymCompleter, coord: Coord = NoCoord) =
24+
final def newLazySymbol[N <: Name](owner: Symbol, name: N, initFlags: FlagSet, completer: SymCompleter, coord: Coord = NoCoord) =
2525
new Symbol(coord, new LazySymDenotation(_, owner, name, initFlags, completer)) {
2626
type ThisName = N
2727
}
2828

29-
def newLazyClassSymbol(owner: Symbol, name: TypeName, initFlags: FlagSet, completer: ClassCompleter, assocFile: AbstractFile = null, coord: Coord = NoCoord) =
29+
final def newLazyClassSymbol(owner: Symbol, name: TypeName, initFlags: FlagSet, completer: ClassCompleter, assocFile: AbstractFile = null, coord: Coord = NoCoord) =
3030
new ClassSymbol(coord, new LazyClassDenotation(_, owner, name, initFlags, completer, assocFile)(this))
3131

32-
def newLazyModuleSymbols(owner: Symbol,
32+
final def newLazyModuleSymbols(owner: Symbol,
3333
name: TermName,
3434
flags: FlagSet,
3535
completer: ClassCompleter,
@@ -47,12 +47,12 @@ trait Symbols { this: Context =>
4747
(module, modcls)
4848
}
4949

50-
def newSymbol[N <: Name](owner: Symbol, name: N, flags: FlagSet, info: Type, privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord) =
50+
final def newSymbol[N <: Name](owner: Symbol, name: N, flags: FlagSet, info: Type, privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord) =
5151
new Symbol(coord, CompleteSymDenotation(_, owner, name, flags, info, privateWithin)) {
5252
type ThisName = N
5353
}
5454

55-
def newClassSymbol(
55+
final def newClassSymbol(
5656
owner: Symbol,
5757
name: TypeName,
5858
flags: FlagSet,
@@ -66,7 +66,7 @@ trait Symbols { this: Context =>
6666
new ClassSymbol(coord, new CompleteClassDenotation(
6767
_, owner, name, flags, parents, privateWithin, optSelfType, decls, assocFile)(this))
6868

69-
def newModuleSymbols(
69+
final def newModuleSymbols(
7070
owner: Symbol,
7171
name: TermName,
7272
flags: FlagSet,
@@ -89,7 +89,7 @@ trait Symbols { this: Context =>
8989
(module, modcls)
9090
}
9191

92-
def newStubSymbol(owner: Symbol, name: Name, file: AbstractFile = null): Symbol = {
92+
final def newStubSymbol(owner: Symbol, name: Name, file: AbstractFile = null): Symbol = {
9393
def stub = new StubCompleter(ctx.condensed)
9494
name match {
9595
case name: TermName => ctx.newLazyModuleSymbols(owner, name, EmptyFlags, stub, file)._1
@@ -99,36 +99,36 @@ trait Symbols { this: Context =>
9999

100100
// ---- Derived symbol creation methods -------------------------------------
101101

102-
def newLazyPackageSymbols(owner: Symbol, name: TermName, completer: ClassCompleter) =
102+
final def newLazyPackageSymbols(owner: Symbol, name: TermName, completer: ClassCompleter) =
103103
newLazyModuleSymbols(owner, name, PackageCreationFlags, completer)
104104

105-
def newPackageSymbols(
105+
final def newPackageSymbols(
106106
owner: Symbol,
107107
name: TermName,
108108
decls: Scope = newScope) =
109109
newModuleSymbols(
110110
owner, name, PackageCreationFlags, PackageCreationFlags, Nil, NoSymbol, decls)
111111

112-
def newLocalDummy(cls: Symbol, coord: Coord = NoCoord) =
112+
final def newLocalDummy(cls: Symbol, coord: Coord = NoCoord) =
113113
newSymbol(cls, nme.localDummyName(cls), EmptyFlags, NoType)
114114

115-
def newImportSymbol(expr: TypedTree, coord: Coord = NoCoord) =
115+
final def newImportSymbol(expr: TypedTree, coord: Coord = NoCoord) =
116116
newSymbol(NoSymbol, nme.IMPORT, EmptyFlags, ImportType(expr), coord = coord)
117117

118-
def newConstructor(cls: ClassSymbol, flags: FlagSet, paramNames: List[TermName], paramTypes: List[Type], privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord) =
118+
final def newConstructor(cls: ClassSymbol, flags: FlagSet, paramNames: List[TermName], paramTypes: List[Type], privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord) =
119119
newSymbol(cls, nme.CONSTRUCTOR, flags, MethodType(paramNames, paramTypes)(_ => cls.typeConstructor), privateWithin, coord)
120120

121-
def newDefaultConstructor(cls: ClassSymbol) =
121+
final def newDefaultConstructor(cls: ClassSymbol) =
122122
newConstructor(cls, EmptyFlags, Nil, Nil)
123123

124-
def newSelfSym(cls: ClassSymbol) =
124+
final def newSelfSym(cls: ClassSymbol) =
125125
ctx.newSymbol(cls, nme.THIS, SyntheticArtifact, cls.selfType)
126126

127127
/** Create new type parameters with given owner, names, and flags.
128128
* @param boundsFn A function that, given type refs to the newly created
129129
* parameters returns a list of their bounds.
130130
*/
131-
def newTypeParams(
131+
final def newTypeParams(
132132
owner: Symbol,
133133
names: List[TypeName],
134134
flags: FlagSet,
@@ -146,37 +146,37 @@ trait Symbols { this: Context =>
146146

147147
// ----- Locating predefined symbols ----------------------------------------
148148

149-
def requiredPackage(path: PreName): TermSymbol =
149+
final def requiredPackage(path: PreName): TermSymbol =
150150
base.staticRef(path.toTermName).requiredSymbol(_.isPackage).asTerm
151151

152-
def requiredClass(path: PreName): ClassSymbol =
152+
final def requiredClass(path: PreName): ClassSymbol =
153153
base.staticRef(path.toTypeName).requiredSymbol(_.isClass).asClass
154154

155-
def requiredModule(path: PreName): TermSymbol =
155+
final def requiredModule(path: PreName): TermSymbol =
156156
base.staticRef(path.toTermName).requiredSymbol(_.isModule).asTerm
157157
}
158158

159159
object Symbols {
160160

161161
/** A Symbol represents a Scala definition/declaration or a package.
162162
*/
163-
class Symbol(val coord: Coord, denotf: Symbol => SymDenotation) extends DotClass {
163+
sealed class Symbol(val coord: Coord, denotf: Symbol => SymDenotation) extends DotClass {
164164

165165
type ThisName <: Name
166166

167167
/** Is symbol different from NoSymbol? */
168168
def exists = true
169169

170170
/** This symbol, if it exists, otherwise the result of evaluating `that` */
171-
def orElse(that: => Symbol) = if (exists) this else that
171+
final def orElse(that: => Symbol) = if (exists) this else that
172172

173173
/** If this symbol satisfies predicate `p` this symbol, otherwise `NoSymbol` */
174-
def filter(p: Symbol => Boolean): Symbol = if (p(this)) this else NoSymbol
174+
final def filter(p: Symbol => Boolean): Symbol = if (p(this)) this else NoSymbol
175175

176176
private[this] var _id: Int = _
177177

178178
/** The unique id of this symbol */
179-
def id(implicit ctx: Context) = {
179+
final def id(implicit ctx: Context) = {
180180
if (_id == 0) _id = ctx.nextId
181181
_id
182182
}
@@ -215,31 +215,31 @@ object Symbols {
215215
}
216216

217217
/** Is symbol a primitive value class? */
218-
def isPrimitiveValueClass(implicit ctx: Context) = defn.ScalaValueClasses contains this
218+
final def isPrimitiveValueClass(implicit ctx: Context) = defn.ScalaValueClasses contains this
219219

220220
/** Is symbol a phantom class for which no runtime representation exists? */
221-
def isPhantomClass(implicit ctx: Context) = defn.PhantomClasses contains this
221+
final def isPhantomClass(implicit ctx: Context) = defn.PhantomClasses contains this
222222

223223
/** The current name of this symbol */
224224
final def name(implicit ctx: Context): ThisName = denot.name.asInstanceOf[ThisName]
225225

226-
def show(implicit ctx: Context): String = ctx.show(this)
227-
def showLocated(implicit ctx: Context): String = ctx.showLocated(this)
228-
def showDcl(implicit ctx: Context): String = ctx.showDcl(this)
229-
def showKind(implicit ctx: Context): String = ctx.showKind(this)
230-
def showName(implicit ctx: Context): String = ctx.showName(this)
231-
def showFullName(implicit ctx: Context): String = ctx.showFullName(this)
226+
final def show(implicit ctx: Context): String = ctx.show(this)
227+
final def showLocated(implicit ctx: Context): String = ctx.showLocated(this)
228+
final def showDcl(implicit ctx: Context): String = ctx.showDcl(this)
229+
final def showKind(implicit ctx: Context): String = ctx.showKind(this)
230+
final def showName(implicit ctx: Context): String = ctx.showName(this)
231+
final def showFullName(implicit ctx: Context): String = ctx.showFullName(this)
232232

233233
}
234234

235235
type TermSymbol = Symbol { type ThisName = TermName }
236236
type TypeSymbol = Symbol { type ThisName = TypeName }
237237

238-
class ClassSymbol(coord: Coord, denotf: ClassSymbol => ClassDenotation) extends Symbol(coord, s => denotf(s.asClass)) {
238+
final class ClassSymbol(coord: Coord, denotf: ClassSymbol => ClassDenotation) extends Symbol(coord, s => denotf(s.asClass)) {
239239

240240
type ThisName = TypeName
241241

242-
final def classDenot(implicit ctx: Context): ClassDenotation =
242+
def classDenot(implicit ctx: Context): ClassDenotation =
243243
denot.asInstanceOf[ClassDenotation]
244244

245245
private var superIdHint: Int = -1
@@ -265,7 +265,7 @@ object Symbols {
265265
}
266266
}
267267

268-
class ErrorSymbol(val underlying: Symbol, msg: => String)(implicit ctx: Context) extends Symbol(NoCoord, sym => underlying.denot) {
268+
final class ErrorSymbol(val underlying: Symbol, msg: => String)(implicit ctx: Context) extends Symbol(NoCoord, sym => underlying.denot) {
269269
type ThisName = underlying.ThisName
270270
}
271271

0 commit comments

Comments
 (0)