diff --git a/tests/neg/tasty-macro-error.check b/tests/neg/tasty-macro-error.check index bd2bc791e85d..2261428580cc 100644 --- a/tests/neg/tasty-macro-error.check +++ b/tests/neg/tasty-macro-error.check @@ -1,16 +1,2 @@ -[486..500] in quoted_2.scala -here is the the argument is _root_.scala.StringContext.apply(("abc", "": scala.[scala#Predef.String])).s(("def": scala.[scala.Any])) -[453..466] in quoted_2.scala -here is the the argument is ("abc": scala.Predef.String) -[407..408] in quoted_2.scala -here is the the argument is d -[386..387] in quoted_2.scala -here is the the argument is c -[309..323] in quoted_2.scala -here is the the argument is _root_.scala.StringContext.apply(("abc", "": scala.[scala#Predef.String])).s(("def": scala.[scala.Any])) -[277..290] in quoted_2.scala -here is the the argument is ("abc": scala.Predef.String) -[233..234] in quoted_2.scala -here is the the argument is d -[213..214] in quoted_2.scala -here is the the argument is c +[117..120] in quoted_2.scala +here is the the argument is foo diff --git a/tests/neg/tasty-macro-error/quoted_1.scala b/tests/neg/tasty-macro-error/quoted_1.scala index c51496d72ae7..fc1808e5ff9d 100644 --- a/tests/neg/tasty-macro-error/quoted_1.scala +++ b/tests/neg/tasty-macro-error/quoted_1.scala @@ -6,20 +6,10 @@ object Macros { inline def fun(x: Any): Unit = ${ impl('x) } - inline def fun2(x: =>Any): Unit = ${ impl('x) } - - inline def fun3[T]: Unit = ${ impl2('[T]) } - def impl(x: Expr[Any])(implicit reflect: Reflection): Expr[Unit] = { import reflect._ error("here is the the argument is " + x.unseal.underlyingArgument.showCode, x.unseal.underlyingArgument.pos) '{} } - def impl2[T](x: quoted.Type[T])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ - error("here is the the argument is " + x.unseal.showCode, x.unseal.pos) - '{} - } - } diff --git a/tests/neg/tasty-macro-error/quoted_2.scala b/tests/neg/tasty-macro-error/quoted_2.scala index a8bbe3000783..a79636e8e51d 100644 --- a/tests/neg/tasty-macro-error/quoted_2.scala +++ b/tests/neg/tasty-macro-error/quoted_2.scala @@ -3,36 +3,9 @@ import Macros._ object Test { def main(args: Array[String]): Unit = { - val a: String = "abc" - val b: 42 = 42 - def c: String = "abc" - def d: 42 = 42 - -// fun(a) // ERROR -// fun(b) // ERROR - fun(c) // error - fun(d) // error -// fun("abc") // ERROR - fun("abc": String) // error - fun(s"abc${"def"}") // error - -// fun2(a) // ERROR -// fun2(b) // ERROR - fun2(c) // error - fun2(d) // error -// fun2("abc") // ERROR - fun2("abc": String) // error - fun2(s"abc${"def"}") // error - -// type T -// type U = "abc" -// -// fun3[T] // ERROR -// fun3[String] // ERROR -// fun3["abc"] // ERROR -// fun3[U] // ERROR + def foo: String = "abc" + fun( + foo // error + ) } -// FIXME all the lines marked as ERROR have the wrong position on the three of the argument. -// they all have as source file this file but the span of `'x` in `fun` or `fun2`. -// see #6026 and #6027 } diff --git a/tests/run/tasty-macro-positions.check b/tests/run/tasty-macro-positions.check new file mode 100644 index 000000000000..dae4b61f268f --- /dev/null +++ b/tests/run/tasty-macro-positions.check @@ -0,0 +1,36 @@ +quoted_2.scala:[103..103] +a +quoted_2.scala:[103..103] +b +quoted_2.scala:[213..214] +c +quoted_2.scala:[224..225] +d +quoted_2.scala:[103..103] +"abc" +quoted_2.scala:[259..272] +("abc": scala.Predef.String) +quoted_2.scala:[282..296] +_root_.scala.StringContext.apply(("abc", "": scala.[scala#Predef.String])).s(("def": scala.[scala.Any])) +quoted_2.scala:[154..154] +a +quoted_2.scala:[154..154] +b +quoted_2.scala:[350..351] +c +quoted_2.scala:[362..363] +d +quoted_2.scala:[154..154] +"abc" +quoted_2.scala:[399..412] +("abc": scala.Predef.String) +quoted_2.scala:[423..437] +_root_.scala.StringContext.apply(("abc", "": scala.[scala#Predef.String])).s(("def": scala.[scala.Any])) +quoted_2.scala:[201..202] +T +quoted_2.scala:[201..202] +scala.Predef.String +quoted_2.scala:[201..202] +"abc" +quoted_2.scala:[201..202] +U diff --git a/tests/run/tasty-macro-positions/quoted_1.scala b/tests/run/tasty-macro-positions/quoted_1.scala new file mode 100644 index 000000000000..e9722ff1d6ae --- /dev/null +++ b/tests/run/tasty-macro-positions/quoted_1.scala @@ -0,0 +1,37 @@ +import scala.quoted._ + +import scala.tasty._ + +object Macros { + + inline def fun(x: Any): Unit = ${ impl('x) } + + inline def fun2(x: =>Any): Unit = ${ impl('x) } + + inline def fun3[T]: Unit = ${ impl2('[T]) } + + def impl(x: Expr[Any])(implicit reflect: Reflection): Expr[Unit] = { + import reflect._ + val pos = x.unseal.underlyingArgument.pos + val code = x.unseal.underlyingArgument.showCode + '{ + println(${posStr(reflect)(pos)}) + println(${code.toExpr}) + } + } + + def impl2[T](x: quoted.Type[T])(implicit reflect: Reflection): Expr[Unit] = { + import reflect._ + val pos = x.unseal.pos + val code = x.unseal.showCode + '{ + println(${posStr(reflect)(pos)}) + println(${code.toExpr}) + } + } + + def posStr(relfection: Reflection)(pos: relfection.Position): Expr[String] = { + import relfection._ + s"${pos.sourceFile.getFileName.toString}:[${pos.start}..${pos.end}]".toExpr + } +} diff --git a/tests/run/tasty-macro-positions/quoted_2.scala b/tests/run/tasty-macro-positions/quoted_2.scala new file mode 100644 index 000000000000..942c4715e404 --- /dev/null +++ b/tests/run/tasty-macro-positions/quoted_2.scala @@ -0,0 +1,38 @@ + +import Macros._ + +object Test { + def main(args: Array[String]): Unit = { + val a: String = "abc" + val b: 42 = 42 + def c: String = "abc" + def d: 42 = 42 + + fun(a) // ERROR + fun(b) // ERROR + fun(c) + fun(d) + fun("abc") // ERROR + fun("abc": String) + fun(s"abc${"def"}") + + fun2(a) // ERROR + fun2(b) // ERROR + fun2(c) + fun2(d) + fun2("abc") // ERROR + fun2("abc": String) + fun2(s"abc${"def"}") + + type T + type U = "abc" + + fun3[T] // ERROR + fun3[String] // ERROR + fun3["abc"] // ERROR + fun3[U] // ERROR + } + // FIXME all the lines marked as ERROR have the wrong position on the three of the argument. + // they all have as source file this file but the span of `'x` in `fun` or `fun2`. + // see #6026 and #6027 +}