Skip to content

Commit ccc6aa3

Browse files
committed
Emit inline errors at expansion site
1 parent 407f9b4 commit ccc6aa3

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ trait MessageRendering {
3333
*/
3434
def outer(pos: SourcePosition, prefix: String)(implicit ctx: Context): List[String] =
3535
if (pos.outer.exists)
36-
i"$prefix| This location is in code that was inlined at ${pos.outer}" ::
36+
i"$prefix| This location is in code that was inlined at $pos" ::
3737
outer(pos.outer, prefix)
3838
else Nil
3939

@@ -149,9 +149,10 @@ trait MessageRendering {
149149
val posString = posStr(pos, diagnosticLevel, msg)
150150
if (posString.nonEmpty) sb.append(posString).append(EOL)
151151
if (pos.exists && pos.source.file.exists) {
152-
val (srcBefore, srcAfter, offset) = sourceLines(pos, diagnosticLevel)
153-
val marker = columnMarker(pos, offset, diagnosticLevel)
154-
val err = errorMsg(pos, msg.msg, offset)
152+
val ompos = if (pos.outermost.contains(pos)) pos else pos.outermost
153+
val (srcBefore, srcAfter, offset) = sourceLines(ompos, diagnosticLevel)
154+
val marker = columnMarker(ompos, offset, diagnosticLevel)
155+
val err = errorMsg(ompos, msg.msg, offset)
155156
sb.append((srcBefore ::: marker :: err :: outer(pos, " " * (offset - 1)) ::: srcAfter).mkString(EOL))
156157
}
157158
else sb.append(msg.msg)

tests/neg/inline-error-pos.check

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
inline def foo(x: Int): Int =
3+
inline x match
4+
case 1 => 9
5+
6+
object Foo {
7+
val a = foo(1)
8+
val b = foo(2) // error
9+
}

tests/neg/inline-error-pos.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
inline def foo(x: Int): Int =
3+
inline x match
4+
case 1 => 9
5+
6+
object Foo {
7+
val a = foo(1)
8+
val b = foo(2) // error
9+
}

0 commit comments

Comments
 (0)