@@ -38,6 +38,12 @@ import annotation.targetName
38
38
39
39
object Symbols {
40
40
41
+ opaque type Symbol >: Null <: SymbolDecl = SymbolImpl
42
+ opaque type ClassSymbol >: Null <: Symbol & ClassSymbolDecl = ClassSymbolImpl
43
+
44
+ type TermSymbol = Symbol { type ThisName = TermName }
45
+ type TypeSymbol = Symbol { type ThisName = TypeName }
46
+
41
47
implicit def eqSymbol : CanEqual [Symbol , Symbol ] = CanEqual .derived
42
48
43
49
/** Tree attachment containing the identifiers in a tree as a sorted array */
@@ -100,6 +106,7 @@ object Symbols {
100
106
101
107
def span : Span
102
108
def sourcePos (using Context ): SourcePosition
109
+ def srcPos : SrcPos
103
110
104
111
def associatedFile (using Context ): AbstractFile
105
112
def binaryFile (using Context ): AbstractFile
@@ -113,7 +120,10 @@ object Symbols {
113
120
def drop ()(using Context ): Unit
114
121
def dropAfter (phase : DenotTransformer )(using Context ): Unit
115
122
116
- inline def orElse (inline that : Symbol )(using Context ): Symbol
123
+ /** This symbol, if it exists, otherwise the result of evaluating `that` */
124
+ inline def orElse (inline that : Symbol )(using Context ): Symbol =
125
+ if denot.exists then this .asInstanceOf [Symbol ] else that
126
+
117
127
def filter (p : Symbol => Boolean ): Symbol
118
128
119
129
// ParamInfo types and methods
@@ -155,7 +165,7 @@ object Symbols {
155
165
* @param coord The coordinates of the symbol (a position or an index)
156
166
* @param id A unique identifier of the symbol (unique per ContextBase)
157
167
*/
158
- class Symbol private [Symbols ] (private var myCoord : Coord , val id : Int )
168
+ class SymbolImpl private [Symbols ] (private var myCoord : Coord , val id : Int )
159
169
extends SymbolDecl {
160
170
161
171
type ThisName <: Name
@@ -354,10 +364,6 @@ object Symbols {
354
364
drop()
355
365
}
356
366
357
- /** This symbol, if it exists, otherwise the result of evaluating `that` */
358
- inline def orElse (inline that : Symbol )(using Context ): Symbol =
359
- if (this .exists) this else that
360
-
361
367
/** If this symbol satisfies predicate `p` this symbol, otherwise `NoSymbol` */
362
368
def filter (p : Symbol => Boolean ): Symbol = if (p(this )) this else NoSymbol
363
369
@@ -413,7 +419,7 @@ object Symbols {
413
419
*
414
420
* @see enclosingSourceSymbols
415
421
*/
416
- @ annotation.tailrec final def sourceSymbol (using Context ): Symbol =
422
+ final def sourceSymbol (using Context ): Symbol =
417
423
if (! denot.exists)
418
424
this
419
425
else if (denot.is(ModuleVal ))
@@ -474,11 +480,8 @@ object Symbols {
474
480
override def hashCode (): Int = id // for debugging.
475
481
}
476
482
477
- type TermSymbol = Symbol { type ThisName = TermName }
478
- type TypeSymbol = Symbol { type ThisName = TypeName }
479
-
480
- class ClassSymbol private [Symbols ] (coord : Coord , val assocFile : AbstractFile , id : Int )
481
- extends Symbol (coord, id), ClassSymbolDecl {
483
+ class ClassSymbolImpl private [Symbols ] (coord : Coord , val assocFile : AbstractFile , id : Int )
484
+ extends SymbolImpl (coord, id), ClassSymbolDecl {
482
485
483
486
type ThisName = TypeName
484
487
@@ -569,7 +572,7 @@ object Symbols {
569
572
}
570
573
571
574
@ sharable
572
- val NoSymbol : Symbol = new Symbol (NoCoord , 0 ) {
575
+ val NoSymbol : Symbol = new SymbolImpl (NoCoord , 0 ) {
573
576
override def associatedFile (using Context ): AbstractFile = NoSource .file
574
577
override def recomputeDenot (lastd : SymDenotation )(using Context ): SymDenotation = NoDenotation
575
578
}
0 commit comments