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

assertTrue macros crashes when macro passed to it #9683

Open
goshacodes opened this issue Mar 10, 2025 · 1 comment
Open

assertTrue macros crashes when macro passed to it #9683

goshacodes opened this issue Mar 10, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@goshacodes
Copy link

goshacodes commented Mar 10, 2025

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(

@goshacodes
Copy link
Author

goshacodes commented Mar 11, 2025

Looks like it is due to this .tree call. Found similar issue in izumi-reflect.
https://github.com/zio/zio/blob/series/2.x/test/shared/src/main/scala-3/zio/test/Macros.scala#L349

zio/izumi-reflect#307

@hearnadam hearnadam added the bug Something isn't working label Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants