Skip to content

Fix the test for error messages #6044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions tests/neg/tasty-macro-error.check
Original file line number Diff line number Diff line change
@@ -1,16 +1,2 @@
[486..500] in quoted_2.scala
here is the the argument is _root_.scala.StringContext.apply(("abc", "": scala.<repeated>[scala#Predef.String])).s(("def": scala.<repeated>[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.<repeated>[scala#Predef.String])).s(("def": scala.<repeated>[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
10 changes: 0 additions & 10 deletions tests/neg/tasty-macro-error/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
'{}
}

}
35 changes: 4 additions & 31 deletions tests/neg/tasty-macro-error/quoted_2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
36 changes: 36 additions & 0 deletions tests/run/tasty-macro-positions.check
Original file line number Diff line number Diff line change
@@ -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.<repeated>[scala#Predef.String])).s(("def": scala.<repeated>[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.<repeated>[scala#Predef.String])).s(("def": scala.<repeated>[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
37 changes: 37 additions & 0 deletions tests/run/tasty-macro-positions/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -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
}
}
38 changes: 38 additions & 0 deletions tests/run/tasty-macro-positions/quoted_2.scala
Original file line number Diff line number Diff line change
@@ -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
}