@@ -25,15 +25,9 @@ trait MessageRendering {
25
25
def stripColor (str : String ): String =
26
26
str.replaceAll(" \u001b\\ [.*?m" , " " )
27
27
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)
37
31
else Nil
38
32
39
33
/** Get the sourcelines before and after the position, as well as the offset
@@ -173,10 +167,17 @@ trait MessageRendering {
173
167
if (pos.exists) {
174
168
val pos1 = pos.nonInlined
175
169
if (pos1.exists && pos1.source.file.exists) {
170
+ // Print error message at inline position
176
171
val (srcBefore, srcAfter, offset) = sourceLines(pos1, levelString)
177
172
val marker = columnMarker(pos1, offset, levelString)
178
173
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) if inlinedPos != pos1 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 ))
180
181
}
181
182
else sb.append(msg.message)
182
183
}
0 commit comments