Skip to content
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

Merged
merged 3 commits into from
Nov 23, 2022
Merged

Use AND PoC. #7310

merged 3 commits into from
Nov 23, 2022

Conversation

Wosin
Copy link
Contributor

@Wosin Wosin commented Sep 4, 2022

This fixes #7260.
The problem described in the issue is related to the fact that in Scala 3, logicall && and || are both mapped to AndThen case class. This PR fixes it so that we can map logical operations to And and Or respectively.

@Wosin Wosin marked this pull request as draft September 4, 2022 12:33
@@ -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
Copy link
Contributor Author

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] =>
Copy link
Contributor Author

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.

Copy link
Contributor Author

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 Wosin marked this pull request as ready for review September 7, 2022 18:25
@jdegoes
Copy link
Member

jdegoes commented Nov 23, 2022

@Wosin Thanks for your work on this!

@adamgfraser Is this good to merge?

@adamgfraser
Copy link
Contributor

@jdegoes Yes lets get this in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Significant differences between rendering of assertTrue(A && B) and assertTrue(A) && assertTrue(B)
3 participants