Skip to content

Commit 77454f8

Browse files
committed
Prepare symbol constructors for unification of Symbols with SymDenotations
1 parent 55e8798 commit 77454f8

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,17 @@ object Denotations {
176176
*
177177
* Then the denotation of `y` is `SingleDenotation(NoSymbol, A | B)`.
178178
*
179-
* @param symbol The referencing symbol, or NoSymbol is none exists
179+
* @param symbolHint The referencing symbol, or NoSymbol is none exists,
180+
* or null, if the Denotation itself is the symbol.
180181
*/
181-
abstract class Denotation(val symbol: Symbol, protected var myInfo: Type, val isType: Boolean)
182+
abstract class Denotation(symbolHint: Symbol | Null, protected var myInfo: Type, val isType: Boolean)
182183
extends PreDenotation, Named, printing.Showable {
183184
type AsSeenFromResult <: Denotation
184185

186+
val symbol: Symbol =
187+
if symbolHint != null then symbolHint
188+
else this.asInstanceOf[Symbol]
189+
185190
/** The type info.
186191
* The info is an instance of TypeType iff this is a type denotation
187192
* Uncompleted denotations set myInfo to a LazyType.
@@ -579,7 +584,7 @@ object Denotations {
579584
end infoMeet
580585

581586
/** A non-overloaded denotation */
582-
abstract class SingleDenotation(symbol: Symbol, initInfo: Type, isType: Boolean) extends Denotation(symbol, initInfo, isType) {
587+
abstract class SingleDenotation(symbolHint: Symbol | Null, initInfo: Type, isType: Boolean) extends Denotation(symbolHint, initInfo, isType) {
583588
protected def newLikeThis(symbol: Symbol, info: Type, pre: Type, isRefinedMethod: Boolean): SingleDenotation
584589

585590
final def name(using Context): ThisName = symbol.name.asInstanceOf[ThisName]

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ object SymDenotations {
4343

4444
//private[SymDenotations]
4545
var defTree: tpd.Tree | Null = null
46-
//private[SymDenotations]
46+
//private[SymDenotations
47+
def isClass: Boolean = isInstanceOf[ClassCommon]
4748
def asClass: ClassCommon = asInstanceOf[ClassCommon]
4849

4950
def reset() =
@@ -69,14 +70,14 @@ object SymDenotations {
6970
* during a period.
7071
*/
7172
class SymDenotation private[SymDenotations] (
72-
symbol: Symbol,
73+
symbolHint: Symbol | Null,
7374
final val common: SymCommon,
7475
final val maybeOwner: Symbol,
7576
final val name: Name,
7677
initFlags: FlagSet,
7778
initInfo: Type,
7879
initPrivateWithin: Symbol = NoSymbol)
79-
extends SingleDenotation(symbol, initInfo, name.isTypeName), ParamInfo, SrcPos, Named {
80+
extends SingleDenotation(symbolHint, initInfo, name.isTypeName), ParamInfo, SrcPos, Named {
8081

8182
//assert(symbol.id != 4940, name)
8283

@@ -1845,14 +1846,14 @@ object SymDenotations {
18451846
/** The contents of a class definition during a period
18461847
*/
18471848
class ClassDenotation private[SymDenotations] (
1848-
symbol: Symbol,
1849+
symbolHint: Symbol | Null,
18491850
common: ClassCommon,
18501851
maybeOwner: Symbol,
18511852
name: Name,
18521853
initFlags: FlagSet,
18531854
initInfo: Type,
18541855
initPrivateWithin: Symbol)
1855-
extends SymDenotation(symbol, common, maybeOwner, name, initFlags, initInfo, initPrivateWithin) {
1856+
extends SymDenotation(symbolHint, common, maybeOwner, name, initFlags, initInfo, initPrivateWithin) {
18561857

18571858
import util.EqHashMap
18581859

@@ -2505,14 +2506,14 @@ object SymDenotations {
25052506
* It overrides ClassDenotation to take account of package objects when looking for members
25062507
*/
25072508
final class PackageClassDenotation private[SymDenotations] (
2508-
symbol: Symbol,
2509+
symbolHint: Symbol | Null,
25092510
common: ClassCommon,
25102511
ownerIfExists: Symbol,
25112512
name: Name,
25122513
initFlags: FlagSet,
25132514
initInfo: Type,
25142515
initPrivateWithin: Symbol)
2515-
extends ClassDenotation(symbol, common, ownerIfExists, name, initFlags, initInfo, initPrivateWithin) {
2516+
extends ClassDenotation(symbolHint, common, ownerIfExists, name, initFlags, initInfo, initPrivateWithin) {
25162517

25172518
private var packageObjsCache: List[ClassDenotation] = _
25182519
private var packageObjsRunId: RunId = NoRunId
@@ -2713,21 +2714,21 @@ object SymDenotations {
27132714
* should be done via this method.
27142715
*/
27152716
def SymDenotation(
2716-
symbol: Symbol,
2717+
symbolHint: Symbol | Null,
27172718
common: SymCommon,
27182719
owner: Symbol,
27192720
name: Name,
27202721
initFlags: FlagSet,
27212722
initInfo: Type,
27222723
initPrivateWithin: Symbol = NoSymbol)(using Context): SymDenotation = {
27232724
val result =
2724-
if symbol.isClass then
2725+
if common.isClass then
27252726
if initFlags.is(Package) then
2726-
new PackageClassDenotation(symbol, common.asClass, owner, name, initFlags, initInfo, initPrivateWithin)
2727+
new PackageClassDenotation(symbolHint, common.asClass, owner, name, initFlags, initInfo, initPrivateWithin)
27272728
else
2728-
new ClassDenotation(symbol, common.asClass, owner, name, initFlags, initInfo, initPrivateWithin)
2729+
new ClassDenotation(symbolHint, common.asClass, owner, name, initFlags, initInfo, initPrivateWithin)
27292730
else
2730-
new SymDenotation(symbol, common, owner, name, initFlags, initInfo, initPrivateWithin)
2731+
new SymDenotation(symbolHint, common, owner, name, initFlags, initInfo, initPrivateWithin)
27312732
result.validFor = currentStablePeriod
27322733
result
27332734
}

0 commit comments

Comments
 (0)