@@ -22,6 +22,7 @@ import config.Config
2222import config .Printers .overload
2323import util .common .*
2424import typer .ProtoTypes .NoViewsAllowed
25+ import reporting .Message
2526import collection .mutable .ListBuffer
2627
2728import scala .compiletime .uninitialized
@@ -954,10 +955,9 @@ object Denotations {
954955 }
955956
956957 def staleSymbolError (using Context ): Nothing =
957- if symbol.isPackageObject && ctx.run != null && ctx.run.nn.isCompilingSuspended then
958- throw TypeError (em " Cyclic macro dependency; macro refers to a toplevel symbol in ${symbol.source} from which the macro is called " )
959- else
960- throw new StaleSymbol (staleSymbolMsg)
958+ if symbol.isPackageObject && ctx.run != null && ctx.run.nn.isCompilingSuspended
959+ then throw StaleSymbolTypeError (symbol)
960+ else throw StaleSymbolException (staleSymbolMsg)
961961
962962 def staleSymbolMsg (using Context ): String = {
963963 def ownerMsg = this match {
@@ -1365,9 +1365,19 @@ object Denotations {
13651365 else
13661366 NoSymbol
13671367
1368+ trait StaleSymbol extends Exception
1369+
13681370 /** An exception for accessing symbols that are no longer valid in current run */
1369- class StaleSymbol (msg : => String ) extends Exception {
1371+ class StaleSymbolException (msg : => String ) extends Exception , StaleSymbol {
13701372 util.Stats .record(" stale symbol" )
13711373 override def getMessage (): String = msg
13721374 }
1375+
1376+ /** An exception that is at the same type a StaleSymbol and a TypeError.
1377+ * Sine it is a TypeError it can be reported as a nroaml error instead of crashing
1378+ * the compiler.
1379+ */
1380+ class StaleSymbolTypeError (symbol : Symbol )(using Context ) extends TypeError , StaleSymbol :
1381+ def toMessage (using Context ) =
1382+ em " Cyclic macro dependency; macro refers to a toplevel symbol in ${symbol.source} from which the macro is called "
13731383}
0 commit comments