@@ -22,6 +22,7 @@ import config.Config
22
22
import config .Printers .overload
23
23
import util .common .*
24
24
import typer .ProtoTypes .NoViewsAllowed
25
+ import reporting .Message
25
26
import collection .mutable .ListBuffer
26
27
27
28
import scala .compiletime .uninitialized
@@ -954,10 +955,9 @@ object Denotations {
954
955
}
955
956
956
957
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)
961
961
962
962
def staleSymbolMsg (using Context ): String = {
963
963
def ownerMsg = this match {
@@ -1365,9 +1365,19 @@ object Denotations {
1365
1365
else
1366
1366
NoSymbol
1367
1367
1368
+ trait StaleSymbol extends Exception
1369
+
1368
1370
/** 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 {
1370
1372
util.Stats .record(" stale symbol" )
1371
1373
override def getMessage (): String = msg
1372
1374
}
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 "
1373
1383
}
0 commit comments