diff --git a/tests/run/reflect-select-copy/assert_1.scala b/tests/run/reflect-select-copy/assert_1.scala new file mode 100644 index 000000000000..498bd48c4c2d --- /dev/null +++ b/tests/run/reflect-select-copy/assert_1.scala @@ -0,0 +1,21 @@ +import scala.quoted._ +import scala.tasty._ + +object scalatest { + + inline def assert(condition: => Boolean): Unit = ~assertImpl('(condition), '("")) + + def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = { + import refl._ + import quoted.Toolbox.Default._ + + cond.unseal.underlyingArgument match { + case Term.Apply(sel @ Term.Select(lhs, op), rhs :: Nil) => + val Term.IsSelect(select) = sel + val cond = Term.Apply(Term.Select.copy(select)(lhs, ">"), rhs :: Nil).seal[Boolean] + '{ scala.Predef.assert(~cond) } + case _ => + '{ scala.Predef.assert(~cond) } + } + } +} \ No newline at end of file diff --git a/tests/run/reflect-select-copy/test_2.scala b/tests/run/reflect-select-copy/test_2.scala new file mode 100644 index 000000000000..435c487885a2 --- /dev/null +++ b/tests/run/reflect-select-copy/test_2.scala @@ -0,0 +1,20 @@ +object Test { + import scalatest._ + + class Box(val x: Int) { + def >(y: Int): Boolean = x > y + def >(b: Box): Boolean = x > b.x + } + + def main(args: Array[String]): Unit = { + val a: Int = 100 + assert(a > 5) + assert(a > 5.0) + assert(a > 'a') + + val b1 = new Box(10) + val b2 = new Box(3) + assert(b1 > 4) + assert(b1 > b2) + } +}