Skip to content

Commit caac6b9

Browse files
Merge pull request #5648 from dotty-staging/refl-select-copy
Add test for Tasty Reflect: Select.copy
2 parents c444f1a + fdf1306 commit caac6b9

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import scala.quoted._
2+
import scala.tasty._
3+
4+
object scalatest {
5+
6+
inline def assert(condition: => Boolean): Unit = ~assertImpl('(condition), '(""))
7+
8+
def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = {
9+
import refl._
10+
import quoted.Toolbox.Default._
11+
12+
cond.unseal.underlyingArgument match {
13+
case Term.Apply(sel @ Term.Select(lhs, op), rhs :: Nil) =>
14+
val Term.IsSelect(select) = sel
15+
val cond = Term.Apply(Term.Select.copy(select)(lhs, ">"), rhs :: Nil).seal[Boolean]
16+
'{ scala.Predef.assert(~cond) }
17+
case _ =>
18+
'{ scala.Predef.assert(~cond) }
19+
}
20+
}
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
object Test {
2+
import scalatest._
3+
4+
class Box(val x: Int) {
5+
def >(y: Int): Boolean = x > y
6+
def >(b: Box): Boolean = x > b.x
7+
}
8+
9+
def main(args: Array[String]): Unit = {
10+
val a: Int = 100
11+
assert(a > 5)
12+
assert(a > 5.0)
13+
assert(a > 'a')
14+
15+
val b1 = new Box(10)
16+
val b2 = new Box(3)
17+
assert(b1 > 4)
18+
assert(b1 > b2)
19+
}
20+
}

0 commit comments

Comments
 (0)