Skip to content

Commit 44fb550

Browse files
committed
Restrict supported binary operators in Dotty
1 parent 973e4de commit 44fb550

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

scalactic.dotty/src/main/scala/org/scalactic/BooleanMacro.scala

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ import scala.quoted._
1919
import scala.tasty._
2020

2121
object BooleanMacro {
22+
private val logicOperators = Set("&&", "||", "&", "|")
23+
24+
private val supportedBinaryOperations =
25+
Set(
26+
"==",
27+
"!=",
28+
"===",
29+
"!==",
30+
"<",
31+
">",
32+
">=",
33+
"<=",
34+
"startsWith",
35+
"endsWith",
36+
"contains",
37+
"eq",
38+
"ne",
39+
"exists") ++ logicOperators
40+
2241
def parse(condition: Expr[Boolean], prettifier: Expr[Prettifier])(implicit refl: Reflection): Expr[Bool] = {
2342
import refl._
2443
import util._
@@ -78,7 +97,7 @@ object BooleanMacro {
7897
case Apply(sel @ Select(lhs, op), rhs :: Nil) =>
7998
def binaryDefault =
8099
if (isByNameMethodType(sel.tpe)) defaultCase
81-
else
100+
else if (supportedBinaryOperations.contains(op))
82101
let(lhs) { left =>
83102
let(rhs) { right =>
84103
val app = left.select(sel.symbol).appliedTo(right)
@@ -91,6 +110,7 @@ object BooleanMacro {
91110
}
92111
}
93112
}.seal.cast[Bool]
113+
else defaultCase
94114

95115
op match {
96116
case "||" =>

0 commit comments

Comments
 (0)