@@ -12,10 +12,22 @@ import Denotations._
12
12
import Decorators ._
13
13
import reporting ._
14
14
import ast .untpd
15
- import config .Printers .cyclicErrors
15
+ import config .Printers .{cyclicErrors , noPrinter }
16
+
17
+ import scala .annotation .constructorOnly
16
18
17
19
abstract class TypeError (using creationContext : Context ) extends Exception (" " ):
18
20
21
+ /** Will the stack trace of this exception be filled in?
22
+ * This is expensive and only useful for debugging purposes.
23
+ */
24
+ def computeStackTrace : Boolean =
25
+ ctx.debug || (cyclicErrors != noPrinter && this .isInstanceOf [CyclicReference ] && ! (ctx.mode is Mode .CheckCyclic ))
26
+
27
+ override def fillInStackTrace (): Throwable =
28
+ if computeStackTrace then super .fillInStackTrace().nn
29
+ else this
30
+
19
31
/** Convert to message. This takes an additional Context, so that we
20
32
* use the context when the message is first produced, i.e. when the TypeError
21
33
* is handled. This makes a difference for CyclicErrors since we need to know
@@ -164,7 +176,7 @@ class CyclicReference private (val denot: SymDenotation)(using Context) extends
164
176
object CyclicReference :
165
177
def apply (denot : SymDenotation )(using Context ): CyclicReference =
166
178
val ex = new CyclicReference (denot)
167
- if ! (ctx.mode is Mode . CheckCyclic ) || ctx.settings. Ydebug .value then
179
+ if ex.computeStackTrace then
168
180
cyclicErrors.println(s " Cyclic reference involving! $denot" )
169
181
val sts = ex.getStackTrace.asInstanceOf [Array [StackTraceElement ]]
170
182
for (elem <- sts take 200 )
0 commit comments