Skip to content

Commit c308a56

Browse files
committed
Fix #5536: Add regression test
1 parent 59d48a3 commit c308a56

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import scala.quoted._
2+
import scala.tasty._
3+
4+
object scalatest {
5+
inline def assert(condition: => Boolean): Unit = ~assertImpl('(condition))
6+
7+
def assertImpl(condition: Expr[Boolean])(implicit refl: Reflection): Expr[Unit] = {
8+
import refl._
9+
import quoted.Toolbox.Default._
10+
11+
val tree = condition.unseal
12+
def exprStr: String = condition.show
13+
14+
tree.underlyingArgument match {
15+
case Term.Apply(Term.Select(lhs, op, _), rhs :: Nil) =>
16+
val left = lhs.seal[Any]
17+
val right = rhs.seal[Any]
18+
op match {
19+
case "===" =>
20+
'{
21+
val _left = ~left
22+
val _right = ~right
23+
val _result = _left == _right
24+
scala.Predef.assert(_result)
25+
}
26+
}
27+
}
28+
}
29+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
class Equalizer[L](val leftSide: L) {
3+
def ===(literalNull: Null): Boolean = leftSide == null
4+
}
5+
6+
object Equality {
7+
implicit def toEqualizer[T](x: T): Equalizer[T] = new Equalizer(x)
8+
}
9+
10+
11+
object Test {
12+
import scalatest._
13+
import Equality._
14+
15+
def main(args: Array[String]): Unit = {
16+
val x = "String"
17+
try assert(x === null)
18+
catch {
19+
case _: AssertionError => // OK
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)