Skip to content
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
21 changes: 21 additions & 0 deletions tests/run/reflect-select-copy/assert_1.scala
Original file line number Diff line number Diff line change
@@ -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) }
}
}
}
20 changes: 20 additions & 0 deletions tests/run/reflect-select-copy/test_2.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}