Skip to content
This repository has been archived by the owner on Mar 16, 2020. It is now read-only.

Macros don't work in Mdoc or when imports are nested #62

Open
ollyw opened this issue Nov 19, 2019 · 0 comments
Open

Macros don't work in Mdoc or when imports are nested #62

ollyw opened this issue Nov 19, 2019 · 0 comments

Comments

@ollyw
Copy link

ollyw commented Nov 19, 2019

When trying to update the zio documentation and using the latest zio-macros, there is an issue that is caused because mdoc wraps code snippets in objects or classes, with the imports inside the class. The error is:

error: ...docs/howto/mock_services.md:188:2: exception during macro expansion: 
scala.reflect.macros.TypecheckException: not found: type ZIO
        at scala.reflect.macros.contexts.Typers.$anonfun$typecheck$3(Typers.scala:44)
        at scala.reflect.macros.contexts.Typers.$anonfun$typecheck$2(Typers.scala:38)
        at scala.reflect.macros.contexts.Typers.doTypecheck$1(Typers.scala:37)
        at scala.reflect.macros.contexts.Typers.typecheck(Typers.scala:51)
        at scala.reflect.macros.contexts.Typers.typecheck$(Typers.scala:32)
  | => dat scala.reflect.macros.contexts.Context.typecheck(Context.scala:18)
	at scala.reflect.macros.contexts.Context.typecheck(Context.scala:18)
	at zio.macros.core.ModulePattern$ZIOExtractor.unapply(ModulePattern.scala:31)
	at zio.macros.core.ModulePattern$$anonfun$extractCapabilities$1.applyOrElse(ModulePattern.scala:152)
	at zio.macros.core.ModulePattern$$anonfun$extractCapabilities$1.applyOrElse(ModulePattern.scala:151)
	at scala.collection.immutable.List.collect(List.scala:308)
	at zio.macros.core.ModulePattern.extractCapabilities(ModulePattern.scala:151)
	at zio.macros.core.ModulePattern.extractCapabilities$(ModulePattern.scala:149)
	at zio.macros.accessible.Macro.extractCapabilities(Macro.scala:23)
	at zio.macros.accessible.Macro.apply(Macro.scala:49)

Here is a simple snippet to recreate:

The following fails:

object Foo {

  import zio._

  trait AccountEvent

  import zio.macros.annotation.{ accessible, mockable }

  @accessible
  @mockable
  trait AccountObserver {
    val accountObserver: AccountObserver.Service[Any]
  }

  object AccountObserver {
    trait Service[R] {
      def processEvent(event: AccountEvent): ZIO[R, Nothing, Unit]
    }
  }
}

Moving the import outside the object succeeds:

import zio._

object Foo {

  trait AccountEvent

  import zio.macros.annotation.{ accessible, mockable }

  @accessible
  @mockable
  trait AccountObserver {
    val accountObserver: AccountObserver.Service[Any]
  }

  object AccountObserver {
    trait Service[R] {
      def processEvent(event: AccountEvent): ZIO[R, Nothing, Unit]
    }
  }
}
ollyw added a commit to ollyw/zio that referenced this issue Nov 19, 2019
* Fix the mocking and use of macros
* Fix incorrect SBT statement
* Update assertions
* Add the test module dependency to the docs to that API breakages are
picked up when the changes are made to the test module

Note that the macro usage in the documentation can't be compiled because
of current limitations of macros, in which they can't be nested. See zio/zio-macros#62
ollyw added a commit to ollyw/zio that referenced this issue Nov 19, 2019
* Fix the mocking and use of macros
* Fix incorrect SBT statement
* Update assertions
* Add the test module dependency to the docs to that API breakages are
picked up when the changes are made to the test module

Note that the macro usage in the documentation can't be compiled because
of current limitations of macros, in which they can't be nested. See zio/zio-macros#62
adamgfraser pushed a commit to zio/zio that referenced this issue Nov 26, 2019
* Fix the mocking and use of macros
* Fix incorrect SBT statement
* Update assertions
* Add the test module dependency to the docs to that API breakages are
picked up when the changes are made to the test module

Note that the macro usage in the documentation can't be compiled because
of current limitations of macros, in which they can't be nested. See zio/zio-macros#62
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant