-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use AND
PoC.
#7310
Use AND
PoC.
#7310
Conversation
@@ -126,6 +126,12 @@ object SmartAssertMacros { | |||
|
|||
def transform[A: Type](expr: Expr[A])(using PositionContext, Quotes) : Expr[TestArrow[Any, A]] = { | |||
import quotes.reflect._ | |||
def isBool(term: quotes.reflect.Term): Boolean = { | |||
term.tpe.widen.asType match { | |||
case '[Boolean] => true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this function, but I have no idea if we can match just particular types in :
case Unseal(MethodCall(lhs, "&&", tpes, Some(List(rhs)))) if isBool(lhs) =>
@@ -173,10 +173,10 @@ class SmartAssertMacros(val c: blackbox.Context) { | |||
case q"!($inner)" => | |||
AST.Not(parseExpr(inner), pos.getPos(tree), pos.getPos(inner)) | |||
|
|||
case q"$lhs && $rhs" => | |||
case q"$lhs && $rhs" if lhs.tpe == typeOf[Boolean] => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sure that if we have a &&
function defined for some type we gonna still handle that in assert true:
object AssertSpec extends ZIOSpecDefault {
override def spec: Spec[Any, Any] =
test("") {
val first = TestClazz(10)
val second = TestClazz(20)
zio.test.assertTrue(first && second)
}
}
case class TestClazz(int: Int){
def &&(anotherClz: TestClazz): Boolean = {
false
}
}
Currently, we are just going to fail compilation for that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, open to propositions if there is a simpler/prettier way to write this.
@Wosin Thanks for your work on this! @adamgfraser Is this good to merge? |
@jdegoes Yes lets get this in! |
This fixes #7260.
The problem described in the issue is related to the fact that in Scala 3, logicall
&&
and||
are both mapped toAndThen
case class. This PR fixes it so that we can map logical operations toAnd
andOr
respectively.