@@ -12,10 +12,22 @@ import Denotations._
1212import Decorators ._
1313import reporting ._
1414import ast .untpd
15- import config .Printers .cyclicErrors
15+ import config .Printers .{cyclicErrors , noPrinter }
16+
17+ import scala .annotation .constructorOnly
1618
1719abstract class TypeError (using creationContext : Context ) extends Exception (" " ):
1820
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+
1931 /** Convert to message. This takes an additional Context, so that we
2032 * use the context when the message is first produced, i.e. when the TypeError
2133 * 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
164176object CyclicReference :
165177 def apply (denot : SymDenotation )(using Context ): CyclicReference =
166178 val ex = new CyclicReference (denot)
167- if ! (ctx.mode is Mode . CheckCyclic ) || ctx.settings. Ydebug .value then
179+ if ex.computeStackTrace then
168180 cyclicErrors.println(s " Cyclic reference involving! $denot" )
169181 val sts = ex.getStackTrace.asInstanceOf [Array [StackTraceElement ]]
170182 for (elem <- sts take 200 )
0 commit comments