@@ -25,15 +25,9 @@ trait MessageRendering {
2525 def stripColor (str : String ): String =
2626 str.replaceAll(" \u001b\\ [.*?m" , " " )
2727
28- /** When inlining a method call, if there's an error we'd like to get the
29- * outer context and the `pos` at which the call was inlined.
30- *
31- * @return a list of strings with inline locations
32- */
33- def outer (pos : SourcePosition , prefix : String )(using Context ): List [String ] =
34- if (pos.outer.exists)
35- i " $prefix| This location contains code that was inlined from $pos" ::
36- outer(pos.outer, prefix)
28+ /** List of all the inline calls that surround the position */
29+ def inlinePosStack (pos : SourcePosition ): List [SourcePosition ] =
30+ if pos.outer.exists then pos :: inlinePosStack(pos.outer)
3731 else Nil
3832
3933 /** Get the sourcelines before and after the position, as well as the offset
@@ -173,10 +167,18 @@ trait MessageRendering {
173167 if (pos.exists) {
174168 val pos1 = pos.nonInlined
175169 if (pos1.exists && pos1.source.file.exists) {
170+ // Print error message at inline position
176171 val (srcBefore, srcAfter, offset) = sourceLines(pos1, levelString)
177172 val marker = columnMarker(pos1, offset, levelString)
178173 val err = errorMsg(pos1, msg.message, offset)
179- sb.append((srcBefore ::: marker :: err :: outer(pos, " " * (offset - 1 )) ::: srcAfter).mkString(EOL ))
174+ sb.append((srcBefore ::: marker :: err :: srcAfter).mkString(EOL ))
175+ // print inline stack trace
176+ for inlinedPos <- inlinePosStack(pos) do
177+ val (srcBefore, srcAfter, offset) = sourceLines(inlinedPos, levelString)
178+ val marker = columnMarker(inlinedPos, offset, levelString)
179+ val prefix = " " * (offset - 1 )
180+ sb.append((i " \n This location contains code that was inlined from $pos" :: srcBefore ::: marker :: srcAfter).mkString(EOL ))
181+
180182 }
181183 else sb.append(msg.message)
182184 }
0 commit comments