question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Macro expansion failure with HigherKinds

See original GitHub issue

I use helpers in my tests to keep things clean such as:

def whenGetById[F[_]](implicit algebra: MyAlgebra[F]): OngoingStubbing[F[Either[MyError, MyResult]]] =
    when(algebra.get(anyVal[My.Id])).delegate

// or on later versions
def whenGetById[F[_]](implicit algebra: MyAlgebra[F]): OngoingStubbing[F[Either[MyError, MyResult]]] =
    when(algebra.get(any[My.Id])).delegate

This worked fine from 0.4.4 (obviously without the delegate call) to 1.0.2. However upon upgrading to any version past 1.0.3 my tests now fail to compile:

[error] /***/MockServices.scala:15:46: exception during macro expansion: 
[error] scala.ScalaReflectionException: type F is not a class
[error]         at scala.reflect.api.Symbols$SymbolApi.asClass(Symbols.scala:272)
[error]         at scala.reflect.api.Symbols$SymbolApi.asClass$(Symbols.scala:272)
[error]         at scala.reflect.internal.Symbols$SymbolContextApiImpl.asClass(Symbols.scala:94)
[error]         at org.mockito.internal.ValueClassExtractor$.materialise(ValueClassExtractor.scala:36)
[error]     when[F[Either[MyError, MyResult]]](merchants.get(anyVal[My.Id])).delegate

Currently I have to work around this with the following method, which allows me to use 1.0.5, but I lost any benefits of using the ScalaOngoingStubbing

private def hkWhen[T](methodCall: T): OngoingStubbing[T] = Mockito.when(methodCall)

I presume this is related to the ValueClassExtractor requirement added to when, which does not work for the F HigherKind.

Moreover, since version 1.0.2? my tests have started spitting out dead code errors on when conditions with value classes – despite stating the types.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bbonannocommented, Dec 17, 2018

@RawToast Thanks for reporting this, v1.0.6 should fix it, please let me know otherwise

Regarding the dead code errors, I don’t have the flag enabled as most of the code throws it so it’s too much noise for me, but I can take a look as in theory it shouldn’t happen if you specify the types, could you please create a separate issue with a full example that I can copy and paste to reproduce the problem?

Thanks

0reactions
bbonannocommented, Dec 18, 2018

@RawToast I see, I got confused cause in my understanding, an algebra is a group of case classes and/or instances of sealed traits, which don’t make a great candidate for mocking, but in your case, you’re mocking services, which is what mocks are for 😃

I’ll have a look to see if this could be built in a more generic way, as here everything but the Either seems configurable

Read more comments on GitHub >

github_iconTop Results From Across the Web

Eager macro-expansion failure in lsp-terraform.el · Issue #3577
I am using the latest version of lsp-mode related packages. · I checked FAQ and Troubleshooting sections · You may also try reproduce...
Read more >
What can cause "Unexpected tree in genLoad" in a macro ...
I was trying to produce a small macro to isolate another problem that I was having and started running into this compile-time error....
Read more >
"Eager macro-expansion failure" message when starting ...
Now when I run emacs & from the terminal, the following message appears. Eager macro-expansion failure: (wrong-number-of-arguments (3 . 4) 2)
Read more >
scala.language.higherKinds Scala Example
NonFatal object Assertions extends DiffExtensions { def fail(message: String): Nothing = throw ... higherKinds import scala.reflect.macros.blackbox trait ...
Read more >
compileTimeOnly - The Scala Programming Language
Examples of potential use: 1) The annottee can only appear in the arguments of some other macro that will eliminate it from the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found