@@ -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
2728/** Denotations represent the meaning of symbols and named types.
@@ -945,10 +946,9 @@ object Denotations {
945946 }
946947
947948 def staleSymbolError (using Context ): Nothing =
948- if symbol.isPackageObject && ctx.run != null && ctx.run.nn.isCompilingSuspended then
949- throw TypeError (em " Cyclic macro dependency; macro refers to a toplevel symbol in ${symbol.source} from which the macro is called " )
950- else
951- throw new StaleSymbol (staleSymbolMsg)
949+ if symbol.isPackageObject && ctx.run != null && ctx.run.nn.isCompilingSuspended
950+ then throw StaleSymbolTypeError (symbol)
951+ else throw StaleSymbolException (staleSymbolMsg)
952952
953953 def staleSymbolMsg (using Context ): String = {
954954 def ownerMsg = this match {
@@ -1356,9 +1356,19 @@ object Denotations {
13561356 else
13571357 NoSymbol
13581358
1359+ trait StaleSymbol extends Exception
1360+
13591361 /** An exception for accessing symbols that are no longer valid in current run */
1360- class StaleSymbol (msg : => String ) extends Exception {
1362+ class StaleSymbolException (msg : => String ) extends Exception , StaleSymbol {
13611363 util.Stats .record(" stale symbol" )
13621364 override def getMessage (): String = msg
13631365 }
1366+
1367+ /** An exception that is at the same type a StaleSymbol and a TypeError.
1368+ * Sine it is a TypeError it can be reported as a nroaml error instead of crashing
1369+ * the compiler.
1370+ */
1371+ class StaleSymbolTypeError (symbol : Symbol )(using Context ) extends TypeError , StaleSymbol :
1372+ def toMessage (using Context ) =
1373+ em " Cyclic macro dependency; macro refers to a toplevel symbol in ${symbol.source} from which the macro is called "
13641374}
0 commit comments