@@ -38,16 +38,21 @@ 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
- opaque type PackageSymbol >: Null <: ClassSymbol = PackageClassSymbolImpl
41
+ object Vault :
42
+
43
+ opaque type Symbol >: Null <: SymbolDecl = SymbolImpl
44
+ opaque type ClassSymbol >: Null <: Symbol & ClassSymbolDecl = ClassSymbolImpl
45
+ opaque type PackageSymbol >: Null <: ClassSymbol = PackageClassSymbolImpl
46
+
47
+ extension (sym : Symbol ) def toSymbolImpl : SymbolImpl = sym
48
+ extension (sym : SymbolImpl ) def fromSymbolImpl : Symbol = sym
49
+
50
+ end Vault
51
+ export Vault ._
44
52
45
53
type TermSymbol = Symbol { type ThisName = TermName }
46
54
type TypeSymbol = Symbol { type ThisName = TypeName }
47
55
48
- extension (sym : Symbol ) def toSymbolImpl : SymbolImpl = sym
49
- extension (sym : SymbolImpl ) def fromSymbolImpl : Symbol = sym
50
-
51
56
implicit def eqSymbol : CanEqual [Symbol , Symbol ] = CanEqual .derived
52
57
53
58
/** Tree attachment containing the identifiers in a tree as a sorted array */
@@ -300,7 +305,7 @@ object Symbols:
300
305
asInstanceOf [TypeSymbol ]
301
306
}
302
307
303
- final def isClass : Boolean = isInstanceOf [ClassSymbol ]
308
+ final def isClass : Boolean = isInstanceOf [ClassSymbol @ unchecked ]
304
309
305
310
final def asClass : ClassSymbol = asInstanceOf [ClassSymbol ]
306
311
@@ -332,7 +337,7 @@ object Symbols:
332
337
/** This symbol entered into owner's scope (owner must be a class). */
333
338
final def entered (using Context ): this .type = {
334
339
if (this .owner.isClass) {
335
- this .owner.asClass.enter(this )
340
+ this .owner.asClass.enter(this .fromSymbolImpl )
336
341
if (this .is(Module )) this .owner.asClass.enter(this .moduleClass)
337
342
}
338
343
this
@@ -360,7 +365,7 @@ object Symbols:
360
365
361
366
/** Remove symbol from scope of owning class */
362
367
final def drop ()(using Context ): Unit = {
363
- this .owner.asClass.delete(this )
368
+ this .owner.asClass.delete(this .fromSymbolImpl )
364
369
if (this .is(Module )) this .owner.asClass.delete(this .moduleClass)
365
370
}
366
371
@@ -379,7 +384,7 @@ object Symbols:
379
384
}
380
385
381
386
/** If this symbol satisfies predicate `p` this symbol, otherwise `NoSymbol` */
382
- def filter (p : Symbol => Boolean ): Symbol = if (p(this )) this else NoSymbol
387
+ def filter (p : Symbol => Boolean ): Symbol = if (p(this .fromSymbolImpl )) this .fromSymbolImpl else NoSymbol
383
388
384
389
/** The current name of this symbol */
385
390
final def name (using Context ): ThisName = denot.name.asInstanceOf [ThisName ]
@@ -433,9 +438,9 @@ object Symbols:
433
438
*
434
439
* @see enclosingSourceSymbols
435
440
*/
436
- final def sourceSymbol (using Context ): SymbolImpl =
441
+ final def sourceSymbol (using Context ): Symbol =
437
442
if (! denot.exists)
438
- this
443
+ this .fromSymbolImpl
439
444
else if (denot.is(ModuleVal ))
440
445
this .moduleClass.sourceSymbol // The module val always has a zero-extent position
441
446
else if (denot.is(Synthetic )) {
@@ -447,7 +452,7 @@ object Symbols:
447
452
}
448
453
else if (denot.isPrimaryConstructor)
449
454
denot.owner.sourceSymbol
450
- else this
455
+ else this .fromSymbolImpl
451
456
452
457
/** The position of this symbol, or NoSpan if the symbol was not loaded
453
458
* from source or from TASTY. This is always a zero-extent position.
@@ -468,7 +473,7 @@ object Symbols:
468
473
def isTypeParam (using Context ): Boolean = denot.is(TypeParam )
469
474
def paramName (using Context ): ThisName = name.asInstanceOf [ThisName ]
470
475
def paramInfo (using Context ): Type = denot.info
471
- def paramInfoAsSeenFrom (pre : Type )(using Context ): Type = pre.memberInfo(this )
476
+ def paramInfoAsSeenFrom (pre : Type )(using Context ): Type = pre.memberInfo(this .fromSymbolImpl )
472
477
def paramInfoOrCompleter (using Context ): Type = denot.infoOrCompleter
473
478
def paramVariance (using Context ): Variance = denot.variance
474
479
def paramRef (using Context ): TypeRef = denot.typeRef
@@ -482,14 +487,14 @@ object Symbols:
482
487
if (lastDenot == null ) s " Naked $prefixString# $id"
483
488
else lastDenot.toString// + "#" + id // !!! DEBUG
484
489
485
- def toText (printer : Printer ): Text = printer.toText(this )
490
+ def toText (printer : Printer ): Text = printer.toText(this .fromSymbolImpl )
486
491
487
- def showLocated (using Context ): String = ctx.printer.locatedText(this ).show
488
- def showExtendedLocation (using Context ): String = ctx.printer.extendedLocationText(this ).show
489
- def showDcl (using Context ): String = ctx.printer.dclText(this ).show
490
- def showKind (using Context ): String = ctx.printer.kindString(this )
491
- def showName (using Context ): String = ctx.printer.nameString(this )
492
- def showFullName (using Context ): String = ctx.printer.fullNameString(this )
492
+ def showLocated (using Context ): String = ctx.printer.locatedText(this .fromSymbolImpl ).show
493
+ def showExtendedLocation (using Context ): String = ctx.printer.extendedLocationText(this .fromSymbolImpl ).show
494
+ def showDcl (using Context ): String = ctx.printer.dclText(this .fromSymbolImpl ).show
495
+ def showKind (using Context ): String = ctx.printer.kindString(this .fromSymbolImpl )
496
+ def showName (using Context ): String = ctx.printer.nameString(this .fromSymbolImpl )
497
+ def showFullName (using Context ): String = ctx.printer.fullNameString(this .fromSymbolImpl )
493
498
494
499
override def hashCode (): Int = id // for debugging.
495
500
}
@@ -567,7 +572,7 @@ object Symbols:
567
572
if file != null && file.extension != " class" then
568
573
mySource = ctx.getSource(file)
569
574
else
570
- mySource = defn.patchSource(this )
575
+ mySource = defn.patchSource(this .fromSymbolImpl )
571
576
if ! mySource.exists then
572
577
mySource = atPhaseNoLater(flattenPhase) {
573
578
denot.topLevelClass.unforcedAnnotation(defn.SourceFileAnnot ) match
@@ -592,7 +597,7 @@ object Symbols:
592
597
val NoSymbol : Symbol = new SymbolImpl (NoCoord , 0 ) {
593
598
override def associatedFile (using Context ): AbstractFile = NoSource .file
594
599
override def recomputeDenot (lastd : SymDenotation )(using Context ): SymDenotation = NoDenotation
595
- }
600
+ }.fromSymbolImpl
596
601
NoDenotation // force it in order to set `denot` field of NoSymbol
597
602
598
603
extension [N <: Name ](sym : Symbol { type ThisName = N })(using Context ) {
@@ -621,9 +626,11 @@ object Symbols:
621
626
622
627
/** Makes all denotation operations available on symbols */
623
628
implicit def toDenot (sym : Symbol )(using Context ): SymDenotation = sym.denot
629
+ implicit def toDenot2 (sym : SymbolImpl )(using Context ): SymDenotation = sym.denot
624
630
625
631
/** Makes all class denotation operations available on class symbols */
626
632
implicit def toClassDenot (cls : ClassSymbol )(using Context ): ClassDenotation = cls.classDenot
633
+ implicit def toClassDenot2 (cls : ClassSymbolImpl )(using Context ): ClassDenotation = cls.classDenot
627
634
628
635
/** The Definitions object */
629
636
def defn (using Context ): Definitions = ctx.definitions
@@ -665,11 +672,12 @@ object Symbols:
665
672
coord : Coord = NoCoord ,
666
673
assocFile : AbstractFile = null )(using Context ): ClassSymbol
667
674
= {
668
- val cls =
675
+ val cls = (
669
676
if flags.is(Package ) then
670
677
new PackageClassSymbolImpl (ctx.base.nextSymId)
671
678
else
672
679
new ClassSymbolImpl (coord, assocFile, ctx.base.nextSymId)
680
+ ).fromSymbolImpl.asClass
673
681
val denot = SymDenotation (cls, owner, name, flags, infoFn(cls), privateWithin)
674
682
cls.denot = denot
675
683
cls
0 commit comments