Skip to content

Commit f2b432e

Browse files
committed
Harden IDE: Avoid ClassCastException in ThisType.cls
This was observed repeatedly as a PC crash.
1 parent e77604d commit f2b432e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,11 @@ object Types {
21772177
* do not survive runs whereas typerefs do.
21782178
*/
21792179
abstract case class ThisType(tref: TypeRef) extends CachedProxyType with SingletonType {
2180-
def cls(implicit ctx: Context): ClassSymbol = tref.stableInRunSymbol.asClass
2180+
def cls(implicit ctx: Context): ClassSymbol = tref.stableInRunSymbol match {
2181+
case cls: ClassSymbol => cls
2182+
case _ if ctx.mode.is(Mode.Interactive) => defn.AnyClass // was observed to happen in IDE mode
2183+
}
2184+
21812185
override def underlying(implicit ctx: Context): Type =
21822186
if (ctx.erasedTypes) tref
21832187
else cls.info match {

0 commit comments

Comments
 (0)