@@ -258,11 +258,8 @@ trait Types
258
258
259
259
/** The base class for all types */
260
260
abstract class Type extends TypeApiImpl with Annotatable [Type ] {
261
- var isDeclaredSingleton : Boolean = false
262
- def asDeclaredSingleton : this .type = {
263
- isDeclaredSingleton = true
264
- this
265
- }
261
+ val isDeclaredSingleton : Boolean = false
262
+ def asDeclaredSingleton : Option [DeclaredSingletonType ] = None
266
263
267
264
/** Types for which asSeenFrom always is the identity, no matter what
268
265
* prefix or owner.
@@ -1817,15 +1814,24 @@ trait Types
1817
1814
class PackageClassInfoType (decls : Scope , clazz : Symbol )
1818
1815
extends ClassInfoType (List (), decls, clazz)
1819
1816
1817
+ final case class DeclaredSingletonType (value : Constant ) extends SingletonType with SingletonTypeApi {
1818
+ override val isDeclaredSingleton = true
1819
+ override def asDeclaredSingleton = Some (this )
1820
+ override def underlying : Type = value.tpe
1821
+ override def isTrivial : Boolean = true
1822
+ override def deconst = underlying
1823
+ override def safeToString : String = value.escapedStringValue + " .type"
1824
+ override def kind = " DeclaredSingletonType"
1825
+ }
1826
+
1820
1827
/** A class representing a constant type.
1821
1828
*/
1822
1829
abstract case class ConstantType (value : Constant ) extends SingletonType with ConstantTypeApi {
1830
+ override def asDeclaredSingleton = Some (DeclaredSingletonType (value))
1823
1831
override def underlying : Type = value.tpe
1824
1832
assert(underlying.typeSymbol != UnitClass )
1825
1833
override def isTrivial : Boolean = true
1826
- override def deconst : Type =
1827
- if (isDeclaredSingleton) this
1828
- else underlying
1834
+ override def deconst : Type = underlying
1829
1835
override def safeToString : String = value.escapedStringValue + " .type"
1830
1836
override def kind = " ConstantType"
1831
1837
}
0 commit comments