@@ -1486,18 +1486,45 @@ object Types {
1486
1486
// --- NamedTypes ------------------------------------------------------------------
1487
1487
1488
1488
/** A NamedType of the form Prefix # name */
1489
- abstract class NamedType extends CachedProxyType with ValueType {
1489
+ abstract class NamedType extends CachedProxyType with ValueType { self =>
1490
+
1491
+ type ThisType >: this .type <: NamedType
1492
+ type ThisName <: Name
1490
1493
1491
1494
val prefix : Type
1492
- val designator : Designator
1495
+ val designator : Designator { type ThisName = self. ThisName }
1493
1496
1494
- def designatorName : Name = designator. asInstanceOf [ Name ]
1497
+ assert(prefix.isValueType || (prefix eq NoPrefix ), s " invalid prefix $prefix " )
1495
1498
1496
- def name (implicit ctx : Context ): Name = designatorName
1499
+ def isType = isInstanceOf [TypeRef ]
1500
+ def isTerm = isInstanceOf [TermRef ]
1497
1501
1498
- type ThisType >: this .type <: NamedType
1502
+ private [this ] var myName : ThisName = _
1503
+ private [this ] var mySig : Signature = null
1504
+
1505
+ def designatorName : Name = designator.asInstanceOf [Name ] // ### todo: remove
1506
+
1507
+ private [dotc] def init ()(implicit ctx : Context ): this .type = {
1508
+ (designator : Designator ) match { // dotty shortcoming: need the upcast
1509
+ case DerivedName (underlying, info : SignedName .SignedInfo ) =>
1510
+ myName = underlying.asInstanceOf [ThisName ]
1511
+ mySig = info.sig
1512
+ assert(mySig ne Signature .OverloadedSignature )
1513
+ case designator : Name =>
1514
+ myName = designator.asInstanceOf [ThisName ]
1515
+ case designator : Symbol =>
1516
+ myName = designator.name.asInstanceOf [ThisName ]
1517
+ uncheckedSetSym(designator)
1518
+ }
1519
+ this
1520
+ }
1499
1521
1500
- assert(prefix.isValueType || (prefix eq NoPrefix ), s " invalid prefix $prefix" )
1522
+ final def name : ThisName = myName
1523
+
1524
+ final override def signature (implicit ctx : Context ): Signature =
1525
+ if (mySig != null ) mySig
1526
+ else if (isType || lastDenotation == null ) Signature .NotAMethod
1527
+ else denot.signature
1501
1528
1502
1529
private [this ] var lastDenotation : Denotation = _
1503
1530
private [this ] var lastSymbol : Symbol = _
@@ -1707,7 +1734,7 @@ object Types {
1707
1734
protected def loadDenot (implicit ctx : Context ): Denotation = {
1708
1735
val d = asMemberOf(prefix, allowPrivate = true )
1709
1736
if (d.exists || ctx.phaseId == FirstPhaseId || ! lastDenotation.isInstanceOf [SymDenotation ])
1710
- if (hasExplicitSignature ) d.atSignature(signature ).checkUnique
1737
+ if (mySig != null ) d.atSignature(mySig ).checkUnique
1711
1738
else d
1712
1739
else { // name has changed; try load in earlier phase and make current
1713
1740
val d = loadDenot(ctx.withPhase(ctx.phaseId - 1 )).current
@@ -1746,9 +1773,6 @@ object Types {
1746
1773
else
1747
1774
denot.symbol
1748
1775
1749
- override def signature (implicit ctx : Context ): Signature =
1750
- if (isType || lastDenotation == null ) Signature .NotAMethod
1751
- else denot.signature
1752
1776
1753
1777
/** Retrieves currently valid symbol without necessarily updating denotation.
1754
1778
* Assumes that symbols do not change between periods in the same run.
@@ -1760,11 +1784,6 @@ object Types {
1760
1784
1761
1785
def info (implicit ctx : Context ): Type = denot.info
1762
1786
1763
- def isType = isInstanceOf [TypeRef ]
1764
- def isTerm = isInstanceOf [TermRef ]
1765
-
1766
- protected def hasExplicitSignature (implicit ctx : Context ) = false
1767
-
1768
1787
/** Guard against cycles that can arise if given `op`
1769
1788
* follows info. The problematic cases are a type alias to itself or
1770
1789
* bounded by itself or a val typed as itself:
@@ -1925,42 +1944,14 @@ object Types {
1925
1944
abstract case class TermRef (override val prefix : Type , designator : TermDesignator ) extends NamedType with SingletonType {
1926
1945
1927
1946
type ThisType = TermRef
1947
+ type ThisName = TermName
1928
1948
1929
1949
// assert(name.toString != "<local Coder>")
1930
1950
override def underlying (implicit ctx : Context ): Type = {
1931
1951
val d = denot
1932
1952
if (d.isOverloaded) NoType else d.info
1933
1953
}
1934
1954
1935
- private var mySig : Signature = null
1936
- private var myName : TermName = null
1937
-
1938
- private def ensureInitialized ()(implicit ctx : Context ): Unit =
1939
- if (myName == null )
1940
- designator match {
1941
- case DerivedName (underlying, info : SignedName .SignedInfo ) =>
1942
- mySig = info.sig
1943
- assert(mySig ne Signature .OverloadedSignature )
1944
- myName = underlying
1945
- case designator : TermName =>
1946
- myName = designator
1947
- case designator : TermSymbol @ unchecked =>
1948
- myName = designator.name
1949
- }
1950
-
1951
- override final def name (implicit ctx : Context ): TermName = {
1952
- ensureInitialized()
1953
- myName
1954
- }
1955
-
1956
- override def hasExplicitSignature (implicit ctx : Context ): Boolean = {
1957
- ensureInitialized()
1958
- mySig != null
1959
- }
1960
-
1961
- override final def signature (implicit ctx : Context ): Signature =
1962
- if (hasExplicitSignature) mySig else super .signature
1963
-
1964
1955
override def isOverloaded (implicit ctx : Context ) = denot.isOverloaded
1965
1956
1966
1957
private def rewrap (sd : SingleDenotation )(implicit ctx : Context ) =
@@ -2005,17 +1996,7 @@ object Types {
2005
1996
abstract case class TypeRef (override val prefix : Type , designator : TypeDesignator ) extends NamedType {
2006
1997
2007
1998
type ThisType = TypeRef
2008
-
2009
- private var myName : TypeName = null
2010
-
2011
- override def name (implicit ctx : Context ): TypeName = {
2012
- if (myName == null )
2013
- myName = designator match {
2014
- case name : TypeName => name
2015
- case sym : TypeSymbol @ unchecked => sym.name
2016
- }
2017
- myName
2018
- }
1999
+ type ThisName = TypeName
2019
2000
2020
2001
override def underlying (implicit ctx : Context ): Type = info
2021
2002
0 commit comments