Skip to content

Commit

Permalink
Merge pull request #13872 from dotty-staging/fix-#13871
Browse files Browse the repository at this point in the history
Add missing position when expanding `error`
  • Loading branch information
anatoliykmetyuk committed Nov 8, 2021
2 parents 045c8bd + 02ddb95 commit 4ad416f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ object Inliner {
lit(error.pos.column),
if kind == ErrorKind.Parser then parserErrorKind else typerErrorKind)

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

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

/** Expand call to scala.compiletime.codeOf */
def codeOf(arg: Tree, pos: SrcPos)(using Context): Tree =
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ i7740a.scala
i7740b.scala
i6507b.scala
i12299a.scala
i13871.scala

# Tree is huge and blows stack for printing Text
i7034.scala
Expand Down
10 changes: 10 additions & 0 deletions tests/pos/i13871.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import scala.compiletime.{error, codeOf}
import scala.compiletime.testing.*

inline def testError(inline typeName: Any): String = error("Got error " + codeOf(typeName))

transparent inline def compileErrors(inline code: String): List[Error] = typeCheckErrors(code)

def test =
typeCheckErrors("""testError("string")""")
compileErrors("""testError("string")""")

0 comments on commit 4ad416f

Please sign in to comment.