Skip to content

Commit 245402d

Browse files
Merge pull request #6462 from dotty-staging/add-sourceCode-test
Add tests for tree.pos.sourceCode
2 parents 863872b + a1a2b10 commit 245402d

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.quoted._
2+
import scala.tasty._
3+
4+
object api {
5+
inline def (x: => T) reflect[T] : String =
6+
${ reflImpl('x) }
7+
8+
private def reflImpl[T](x: Expr[T])(implicit refl: Reflection): Expr[String] = {
9+
import refl._
10+
x.unseal.pos.sourceCode.toExpr
11+
}
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import api._
2+
3+
object Test {
4+
def f(implicit x: Int): Int = x * x
5+
def main(args: Array[String]): Unit = {
6+
implicit val x: Int = 10
7+
assert(args(0).reflect == "args(0)")
8+
assert(args( 0 ).reflect == "args( 0 )")
9+
assert(args( 0 /* ignore */).reflect == "args( 0 /* ignore */)")
10+
assert(f.reflect == "f")
11+
assert((f).reflect == "f")
12+
assert( { f }.reflect == "{ f }")
13+
assert( { f; f }.reflect == "{ f; f }")
14+
}
15+
}

0 commit comments

Comments
 (0)