Skip to content

Commit 4ad416f

Browse files
Merge pull request #13872 from dotty-staging/fix-#13871
Add missing position when expanding `error`
2 parents 045c8bd + 02ddb95 commit 4ad416f

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ object Inliner {
367367
lit(error.pos.column),
368368
if kind == ErrorKind.Parser then parserErrorKind else typerErrorKind)
369369

370-
private def packErrors(errors: List[(ErrorKind, Error)])(using Context): Tree =
370+
private def packErrors(errors: List[(ErrorKind, Error)], pos: SrcPos)(using Context): Tree =
371371
val individualErrors: List[Tree] = errors.map(packError)
372-
val errorTpt = ref(defn.CompiletimeTesting_ErrorClass)
372+
val errorTpt = ref(defn.CompiletimeTesting_ErrorClass).withSpan(pos.span)
373373
mkList(individualErrors, errorTpt)
374374

375375
/** Expand call to scala.compiletime.testing.typeChecks */
@@ -380,7 +380,7 @@ object Inliner {
380380
/** Expand call to scala.compiletime.testing.typeCheckErrors */
381381
def typeCheckErrors(tree: Tree)(using Context): Tree =
382382
val errors = compileForErrors(tree)
383-
packErrors(errors)
383+
packErrors(errors, tree)
384384

385385
/** Expand call to scala.compiletime.codeOf */
386386
def codeOf(arg: Tree, pos: SrcPos)(using Context): Tree =

compiler/test/dotc/pos-test-pickling.blacklist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ i7740a.scala
1717
i7740b.scala
1818
i6507b.scala
1919
i12299a.scala
20+
i13871.scala
2021

2122
# Tree is huge and blows stack for printing Text
2223
i7034.scala

tests/pos/i13871.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import scala.compiletime.{error, codeOf}
2+
import scala.compiletime.testing.*
3+
4+
inline def testError(inline typeName: Any): String = error("Got error " + codeOf(typeName))
5+
6+
transparent inline def compileErrors(inline code: String): List[Error] = typeCheckErrors(code)
7+
8+
def test =
9+
typeCheckErrors("""testError("string")""")
10+
compileErrors("""testError("string")""")

0 commit comments

Comments
 (0)