From 02ddb9556ca60bb28c5d36442424c925b29b3f24 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 3 Nov 2021 16:15:00 +0100 Subject: [PATCH] Add missing position when expanding `error` Closes #13871. This issue was already fixed but failed `-Ycheck` due to the missing position. --- compiler/src/dotty/tools/dotc/typer/Inliner.scala | 6 +++--- compiler/test/dotc/pos-test-pickling.blacklist | 1 + tests/pos/i13871.scala | 10 ++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 tests/pos/i13871.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index b4264dee6e64..4fede9b6b9e4 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -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 */ @@ -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 = diff --git a/compiler/test/dotc/pos-test-pickling.blacklist b/compiler/test/dotc/pos-test-pickling.blacklist index 7136b2f7ac74..9c94e5968fce 100644 --- a/compiler/test/dotc/pos-test-pickling.blacklist +++ b/compiler/test/dotc/pos-test-pickling.blacklist @@ -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 diff --git a/tests/pos/i13871.scala b/tests/pos/i13871.scala new file mode 100644 index 000000000000..3b1ed0f1f06c --- /dev/null +++ b/tests/pos/i13871.scala @@ -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")""")