From f2b432e21676513a2b738dc225210fb0dcde6ce9 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 25 Apr 2018 18:55:14 +0200 Subject: [PATCH] Harden IDE: Avoid ClassCastException in ThisType.cls This was observed repeatedly as a PC crash. --- compiler/src/dotty/tools/dotc/core/Types.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index b465510f1866..ecbd9e18dc68 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -2177,7 +2177,11 @@ object Types { * do not survive runs whereas typerefs do. */ abstract case class ThisType(tref: TypeRef) extends CachedProxyType with SingletonType { - def cls(implicit ctx: Context): ClassSymbol = tref.stableInRunSymbol.asClass + def cls(implicit ctx: Context): ClassSymbol = tref.stableInRunSymbol match { + case cls: ClassSymbol => cls + case _ if ctx.mode.is(Mode.Interactive) => defn.AnyClass // was observed to happen in IDE mode + } + override def underlying(implicit ctx: Context): Type = if (ctx.erasedTypes) tref else cls.info match {