Skip to content

Commit da3b5fb

Browse files
committed
Make it safe to call Tree#symbol and Tree#denot on an untyped tree
This is a more general fix than what the previous commit did.
1 parent 8923efc commit da3b5fb

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ object Trees {
233233
/** Tree's denotation can be derived from its type */
234234
abstract class DenotingTree[-T >: Untyped] extends Tree[T] {
235235
type ThisTree[-T >: Untyped] <: DenotingTree[T]
236-
override def denot(implicit ctx: Context) = tpe match {
236+
override def denot(implicit ctx: Context) = typeOpt match {
237237
case tpe: NamedType => tpe.denot
238238
case tpe: ThisType => tpe.cls.denot
239239
case tpe: AnnotatedType => tpe.stripAnnots match {
@@ -363,7 +363,7 @@ object Trees {
363363
type ThisTree[-T >: Untyped] = This[T]
364364
// Denotation of a This tree is always the underlying class; needs correction for modules.
365365
override def denot(implicit ctx: Context): Denotation = {
366-
tpe match {
366+
typeOpt match {
367367
case tpe @ TermRef(pre, _) if tpe.symbol is Module =>
368368
tpe.symbol.moduleClass.denot.asSeenFrom(pre)
369369
case _ =>

compiler/src/dotty/tools/dotc/typer/FrontEnd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class FrontEnd extends Phase {
7070
private def firstTopLevelDef(trees: List[tpd.Tree])(implicit ctx: Context): Symbol = trees match {
7171
case PackageDef(_, defs) :: _ => firstTopLevelDef(defs)
7272
case Import(_, _) :: defs => firstTopLevelDef(defs)
73-
case (tree @ TypeDef(_, _)) :: _ => if (tree.hasType) tree.symbol else NoSymbol
73+
case (tree @ TypeDef(_, _)) :: _ => tree.symbol
7474
case _ => NoSymbol
7575
}
7676

0 commit comments

Comments
 (0)