Skip to content

Commit 8ea5836

Browse files
committed
Fix #1604: print outer context if applicable
1 parent 26e98d3 commit 8ea5836

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/dotty/tools/dotc/reporting/MessageRendering.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ trait MessageRendering {
1515
def stripColor(str: String): String =
1616
str.replaceAll("\u001B\\[[;\\d]*m", "")
1717

18+
def outer(pos: SourcePosition, prefix: String)(implicit ctx: Context): List[String] =
19+
if (pos.outer.exists) {
20+
s"$prefix| This location is in code that was inlined at ${pos.outer}" ::
21+
outer(pos.outer, prefix)
22+
} else Nil
23+
1824
def sourceLines(pos: SourcePosition)(implicit ctx: Context): (List[String], List[String], Int) = {
1925
var maxLen = Int.MinValue
2026
def render(xs: List[Int]) =
@@ -92,7 +98,7 @@ trait MessageRendering {
9298
val (srcBefore, srcAfter, offset) = sourceLines(pos)
9399
val marker = columnMarker(pos, offset)
94100
val err = errorMsg(pos, msg.msg, offset)
95-
sb.append((srcBefore ::: marker :: err :: srcAfter).mkString("\n"))
101+
sb.append((srcBefore ::: marker :: err :: outer(pos, " " * (offset - 1)) ::: srcAfter).mkString("\n"))
96102
} else sb.append(msg.msg)
97103
sb.toString
98104
}

src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,12 @@ object Inliner {
236236
def inlineCall(tree: Tree, pt: Type)(implicit ctx: Context): Tree =
237237
if (enclosingInlineds.length < ctx.settings.xmaxInlines.value)
238238
new Inliner(tree, bodyToInline(tree.symbol)).inlined(pt)
239-
else errorTree(tree,
240-
i"""Maximal number of successive inlines (${ctx.settings.xmaxInlines.value}) exceeded,
241-
| Maybe this is caused by a recursive inline method?
242-
| You can use -Xmax:inlines to change the limit.""")
239+
else errorTree(
240+
tree,
241+
i"""|Maximal number of successive inlines (${ctx.settings.xmaxInlines.value}) exceeded,
242+
|Maybe this is caused by a recursive inline method?
243+
|You can use -Xmax:inlines to change the limit."""
244+
)
243245

244246
/** Replace `Inlined` node by a block that contains its bindings and expansion */
245247
def dropInlined(inlined: tpd.Inlined)(implicit ctx: Context): Tree = {

0 commit comments

Comments
 (0)