@@ -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
/** Denotations represent the meaning of symbols and named types.
@@ -945,10 +946,9 @@ object Denotations {
945
946
}
946
947
947
948
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)
952
952
953
953
def staleSymbolMsg (using Context ): String = {
954
954
def ownerMsg = this match {
@@ -1356,9 +1356,19 @@ object Denotations {
1356
1356
else
1357
1357
NoSymbol
1358
1358
1359
+ trait StaleSymbol extends Exception
1360
+
1359
1361
/** 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 {
1361
1363
util.Stats .record(" stale symbol" )
1362
1364
override def getMessage (): String = msg
1363
1365
}
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 "
1364
1374
}
0 commit comments