Skip to content

Commit f70b87f

Browse files
committed
Harden new caching scheme against fuzzing
1 parent e405898 commit f70b87f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,11 +1189,15 @@ object SymDenotations {
11891189
cachedRef
11901190
}
11911191

1192-
override def typeRef(implicit ctx: Context): TypeRef =
1193-
namedRef.asInstanceOf[TypeRef]
1192+
override def typeRef(implicit ctx: Context): TypeRef = namedRef match {
1193+
case ref: TypeRef => ref
1194+
case _ => defn.AnyClass.typeRef // case arises when compiling parser-stabiility-1.scala
1195+
}
11941196

1195-
override def termRef(implicit ctx: Context): TermRef =
1196-
namedRef.asInstanceOf[TermRef]
1197+
override def termRef(implicit ctx: Context): TermRef = namedRef match {
1198+
case ref: TermRef => ref
1199+
case _ => defn.EmptyPackageVal.termRef
1200+
}
11971201

11981202
/** The variance of this type parameter or type member as an Int, with
11991203
* +1 = Covariant, -1 = Contravariant, 0 = Nonvariant, or not a type parameter

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ object Uniques {
6666
designator match {
6767
case sym: Symbol =>
6868
val symd = sym.lastKnownDenotation
69-
if (symd != null) {
69+
if (symd != null && symd.exists) {
7070
val ref = symd.namedRef
7171
if (prefix `eq` ref.prefix) {
7272
record("namedRef reuse")

0 commit comments

Comments
 (0)