Thanks to visit codestin.com
Credit goes to github.com

Skip to content

assertTrue macros crashes when macro passed to it #9683

@goshacodes

Description

@goshacodes

Sorry, was not able to minimize, so there would be no dependency on scalamock.
This bug makes integration of scalamock with zio-test problematic.

lazy val root = (project in file("."))
  .settings(
    scalaVersion := "3.6.3",
    name := "zio-test-example",
    libraryDependencies ++= Seq(
      "dev.zio" %% "zio" % "2.1.16",
      "dev.zio" %% "zio-test" % "2.1.16" % Test,
      "org.scalamock" %% "scalamock-zio" % "7.3.0-RC4" % Test
    )
  )
import zio.*
import zio.test.*
import org.scalamock.stubs.ZIOStubs

trait IntService {
  def foo(clientId: String): Task[Boolean]
}


object MySpec extends ZIOSpecDefault, ZIOStubs {

  override def spec: Spec[TestEnvironment & Scope, Any] =
    suite("MySpec")(
      test("MyTest") {
        val intServiceStub = stub[IntService]
        for {
          _ <- stubbed(intServiceStub.foo).returnsZIO(_ => ZIO.succeed(true))
        } yield assertTrue(
          stubbed(intServiceStub.foo).times == 0
        )
      }
    )
}

It is strange, because if I change stubbed(intServiceStub.foo).times == 0 to stubbed(intServiceStub.foo).calls.isEmpty everything compiles just fine

Exception occurred while executing macro expansion.
java.lang.AssertionError: assertion failed: Cannot get tree of no symbol
	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
	at dotty.tools.dotc.quoted.reflect.FromSymbol$.definitionFromSym(FromSymbol.scala:15)
	at scala.quoted.runtime.impl.QuotesImpl$reflect$SymbolMethods$.tree(QuotesImpl.scala:2716)
	at scala.quoted.runtime.impl.QuotesImpl$reflect$SymbolMethods$.tree(QuotesImpl.scala:2716)
	at zio.test.SmartAssertMacros$.body$1(Macros.scala:349)
	at zio.test.SmartAssertMacros$.$anonfun$17$$anonfun$1(Macros.scala:374)
	at zio.test.SmartAssertMacros$.$anonfun$17(Macros.scala:374)
	at zio.test.SmartAssertMacros$.$anonfun$adapted$17(Macros.scala:374)
	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:111)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1571)
	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
	at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock$$anonfun$1$$anonfun$1(tpd.scala:1294)
	at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1276)
	at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1289)
	at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock(tpd.scala:1294)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1551)
	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1603)
	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
	at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1289)
	at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1289)
	at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock(tpd.scala:1294)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1551)
	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
	at dotty.tools.dotc.quoted.PickledQuotes$.spliceTerms(PickledQuotes.scala:153)
	at dotty.tools.dotc.quoted.PickledQuotes$.unpickleTerm(PickledQuotes.scala:89)
	at scala.quoted.runtime.impl.QuotesImpl.unpickleExprV2(QuotesImpl.scala:3280)
	at zio.test.SmartAssertMacros$.transform(Macros.scala:374)
	at zio.test.SmartAssertMacros$.transform$$anonfun$14(Macros.scala:312)
	at zio.test.SmartAssertMacros$.transform$$anonfun$adapted$14(Macros.scala:314)
	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:111)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1571)
	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1531)
	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1539)
	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1537)
	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
	at dotty.tools.dotc.quoted.PickledQuotes$.spliceTerms(PickledQuotes.scala:153)
	at dotty.tools.dotc.quoted.PickledQuotes$.unpickleTerm(PickledQuotes.scala:89)
	at scala.quoted.runtime.impl.QuotesImpl.unpickleExprV2(QuotesImpl.scala:3280)
	at zio.test.SmartAssertMacros$.transform(Macros.scala:314)
	at zio.test.SmartAssertMacros$.smartAssertSingle_impl(Macros.scala:398)
	at zio.test.SmartAssertMacros$.smartAssert_impl(Macros.scala:410)
	at zio.test.SmartAssertMacros$.smartAssert(Macros.scala:32)


        } yield assertTrue(

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions