Skip to content

Commit 8923efc

Browse files
committed
Fix #2292: Do not crash when a top-level class is untyped
This can happen when the class is in a package that got an error type.
1 parent de53e52 commit 8923efc

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

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(_, _)) :: _ => tree.symbol
73+
case (tree @ TypeDef(_, _)) :: _ => if (tree.hasType) tree.symbol else NoSymbol
7474
case _ => NoSymbol
7575
}
7676

tests/neg/i2292.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package + // error
2+
3+
class Foo

0 commit comments

Comments
 (0)