Skip to content

Commit 892e1a9

Browse files
committed
Make Singleton an erased class only under modularity import
1 parent 15e003a commit 892e1a9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package core
55
import TypeErasure.ErasedValueType
66
import Types.*, Contexts.*, Symbols.*, Flags.*, Decorators.*
77
import Names.Name
8+
import config.Feature
89

910
class TypeUtils:
1011
/** A decorator that provides methods on types
@@ -19,7 +20,11 @@ class TypeUtils:
1920
self.classSymbol.isPrimitiveValueClass
2021

2122
def isErasedClass(using Context): Boolean =
22-
self.underlyingClassRef(refinementOK = true).typeSymbol.is(Flags.Erased)
23+
val cls = self.underlyingClassRef(refinementOK = true).typeSymbol
24+
cls.is(Flags.Erased)
25+
&& (cls != defn.SingletonClass || Feature.enabled(Feature.modularity))
26+
// Singleton counts as an erased class only under x.modularity
27+
2328

2429
/** Is this type a checked exception? This is the case if the type
2530
* derives from Exception but not from RuntimeException. According to
@@ -144,7 +149,7 @@ class TypeUtils:
144149
def isThisTypeOf(cls: Symbol)(using Context) = self match
145150
case self: Types.ThisType => self.cls == cls
146151
case _ => false
147-
152+
148153
/** Strip all outer refinements off this type */
149154
def stripRefinement: Type = self match
150155
case self: RefinedOrRecType => self.parent.stripRefinement

0 commit comments

Comments
 (0)