play-json-derived-codecs icon indicating copy to clipboard operation
play-json-derived-codecs copied to clipboard

"could not find Lazy implicit value" on incremental compile

Open akitaylor opened this issue 9 years ago • 17 comments
trafficstars

Hi!

I'm facing a strange problem, namely the following problem occures sometimes on inctremental build, but usually a full rebuild solves it:

[error] D:\projektek\Beelend\hg\beelend\app\models\events\EventLogType.scala:174: could not find Lazy implicit value of type julienrf.json.derived.DerivedReads[models.events.EventInfo]
[error]   implicit val fmtLogItemRead: Reads[EventInfo] = derived.reads[EventInfo].orElse(Reads.pure(UnknownEventInfo()))
[error]                                                                ^
[error] D:\projektek\Beelend\hg\beelend\app\models\events\EventLogType.scala:175: possible missing interpolator: detected an interpolated expression
[error]   implicit val fmtLogItemWrite: OWrites[EventInfo] = derived.owrites[EventInfo]

Anyway thanks for the great library.

Regards, Akos

akitaylor avatar Aug 12 '16 07:08 akitaylor

Hi, thanks for reporting. I think this is more a problem of the way the incremental build works, though…

julienrf avatar Aug 12 '16 08:08 julienrf

Hi, as I experienced lately, the problem also occures in full rebuilds, but after 2 or 3 tries usually succeeds to build it. Is there some kind of nondeterministic algorithm in the build process? Is there a way I can debug the build process or acquire debug information about the problem?

akitaylor avatar Sep 01 '16 09:09 akitaylor

According to this discussion with Miles: https://gitter.im/milessabin/shapeless?at=57c7f646d52261ec34463b0a Could you try with typelevel/scala and report any improvement here?

julienrf avatar Sep 01 '16 09:09 julienrf

Thanks, I have tried the typelevel scala compiler. When running the Play allpication in Intellij the same happens:

[info] Compiling 204 Scala sources and 2 Java sources to D:\projektek\Beelend\hg\beelend\target\scala-2.11\classes...
[error] D:\projektek\Beelend\hg\beelend\app\models\events\EventLogType.scala:177: could not find Lazy implicit value of type julienrf.json.derived.DerivedReads[models.events.EventInfo]
[error]   implicit val fmtLogItemRead: Reads[EventInfo] = derived.reads[EventInfo].orElse(Reads.pure(UnknownEventInfo()))
[error]                                                                ^
[error] D:\projektek\Beelend\hg\beelend\app\models\events\EventLogType.scala:178: possible missing interpolator: detected an interpolated expression
[error]   implicit val fmtLogItemWrite: OWrites[EventInfo] = derived.owrites[EventInfo]
[error]                ^
[error] D:\projektek\Beelend\hg\beelend\app\models\events\EventLogType.scala:178: could not find Lazy implicit value of type julienrf.json.derived.DerivedOWrites[models.events.EventInfo]
[error]   implicit val fmtLogItemWrite: OWrites[EventInfo] = derived.owrites[EventInfo]
[error]                                                                     ^
[error] three errors found
[error] (compile:compileIncremental) Compilation failed

Compilation in activator seems to work, at least I could not reproduce the problem.

akitaylor avatar Sep 01 '16 10:09 akitaylor

Do you also have the problem when you compile from activator without using typelevel/scala?

julienrf avatar Sep 01 '16 10:09 julienrf

Well, I tried to compile with activator on a linux machine and the problem also occures with typelevel compiler:

[beelend] $ compile
[info] Updating {file:/home/beelend/hg/beelend/}beelend...
[info] Resolving jline#jline;2.12.1 ...
[info] downloading https://repo1.maven.org/maven2/org/typelevel/scala-library/2.11.8/scala-library-2.11.8.jar ...
[info]  [SUCCESSFUL ] org.typelevel#scala-library;2.11.8!scala-library.jar (436ms)
[info] downloading https://repo1.maven.org/maven2/org/typelevel/scala-reflect/2.11.8/scala-reflect-2.11.8.jar ...
[info]  [SUCCESSFUL ] org.typelevel#scala-reflect;2.11.8!scala-reflect.jar (297ms)
[info] downloading https://repo1.maven.org/maven2/org/typelevel/scala-compiler/2.11.8/scala-compiler-2.11.8.jar ...
[info]  [SUCCESSFUL ] org.typelevel#scala-compiler;2.11.8!scala-compiler.jar (952ms)
[info] Done updating.
[warn] There may be incompatibilities among your library dependencies.
[warn] Here are some of the libraries that were evicted:
[warn]  * org.webjars:jquery:(2.1.4, [1.9.1,), 1.11.1) -> 2.2.1
[warn]  * org.webjars:bootstrap:(3.3.5, 3.2.0, 3.0.3, 2.3.0, 3.0.0) -> 3.3.6
[warn] Run 'evicted' to see detailed eviction warnings
[info] Compiling 204 Scala sources and 2 Java sources to /home/beelend/hg/beelend/target/scala-2.11/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.11.8. Compiling...
[info]   Compilation completed in 16.51 s
[error] /home/beelend/hg/beelend/app/models/events/EventLogType.scala:177: could not find Lazy implicit value of type julienrf.json.derived.DerivedReads[models.events.EventInfo]
[error]   implicit val fmtLogItemRead: Reads[EventInfo] = derived.reads[EventInfo].orElse(Reads.pure(UnknownEventInfo()))
[error]                                                                ^
[error] /home/beelend/hg/beelend/app/models/events/EventLogType.scala:178: possible missing interpolator: detected an interpolated expression
[error]   implicit val fmtLogItemWrite: OWrites[EventInfo] = derived.owrites[EventInfo]
[error]                ^
[error] /home/beelend/hg/beelend/app/models/events/EventLogType.scala:178: could not find Lazy implicit value of type julienrf.json.derived.DerivedOWrites[models.events.EventInfo]
[error]   implicit val fmtLogItemWrite: OWrites[EventInfo] = derived.owrites[EventInfo]
[error]                                                                     ^
[error] three errors found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 88 s, completed Sep 1, 2016 1:28:03 PM

akitaylor avatar Sep 01 '16 11:09 akitaylor

Can you share a minimal test case that reproduces the problem?

julienrf avatar Sep 01 '16 11:09 julienrf

I'm running into what seems to be the same issue even after switching to the typelevel compiler. Going to try to create a simple standalone repo that reproduces the issue and if I'm successful will post a link to it here.

matthull avatar Oct 26 '16 19:10 matthull

I would be grateful if you could make a test case. I tried to isolate the problem, but unfortunately the problem disappeared when I made the application simpler. I suspect that the problem is related to the complexity of other codes that might influence the order/mode of compilation of the Json macros.

Some additional info in my case: I use play Json formatter and the derived codecs mixed, and the case classes (that are converted to Json) are spread in multiple source files. Usually two or three tries of compiling make the problem go away.

akitaylor avatar Oct 26 '16 21:10 akitaylor

@akitaylor I stopped getting this error when I completely eliminated Play Json.format in favor of derived.oformat. Mind you I don't consistently see an issue when mixing format and oformat but getting rid of format seemed to do the trick (so far.)

And now I'm having trouble reproducing the issue even when I start incrementally reverting from format to oformat...

matthull avatar Oct 27 '16 02:10 matthull

Hi,

Anyone had any luck solving this issue? We're also running into this with v4.0.0 version alongside Play 2.6.x.

Thanks!

yarondav avatar Feb 20 '18 16:02 yarondav

Unfortunatelly I could not create a test case to reproduce the problem, as it only seems to occur in complex compilation process (eg. more than 200 source files). The problem is still present after migration to Play 2.6, but only after cleaning the project. The second compilation is usually succeessful.

Regards, Akos

      1. 17:07 keltezéssel, yarondav írta:

Hi,

Anyone had any luck solving this issue? We're also running into this with v4.0.0 version alongside Play 2.6.x.

Thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/julienrf/play-json-derived-codecs/issues/38#issuecomment-367027162, or mute the thread https://github.com/notifications/unsubscribe-auth/AHryV4eHl0Vo0PUOep2wh-5lakT0NR_Mks5tWu3DgaJpZM4Ji2k8.

akitaylor avatar Feb 20 '18 18:02 akitaylor

Strange issue. Just get across to it. I'll see what I can do for it.

WayneWang12 avatar Apr 17 '18 11:04 WayneWang12

I found that sealed is required. Otherwise this error will occur. I think it's better to elaborate this on the document.

WayneWang12 avatar Apr 18 '18 02:04 WayneWang12

And also remember to put every sealed trait to seperate files. Otherwise there may be errors like java.util.NoSuchElementException: value inst$macro$2, especially when you are using this library in a scala.js project.

WayneWang12 avatar Apr 18 '18 03:04 WayneWang12

Hi Wayne! Thanks for the investigation. In our system the attached file is the trigger of the problem. As you can see we use sealed abstract classes and case classes inherit these. It is strange that the problem only occurs after SBT clean, the second compilation is usually successful. It is also an important circumstance, that the project contains 200+ scala classes, it might not show up in smaller projects.

Here is what we get: [warn] Run 'evicted' to see detailed eviction warnings [info] Compiling 231 Scala sources and 3 Java sources to D:\myproject\hg\myproject\target\scala-2.11\classes... [warn] D:\myproject\hg\myproject\app\models\events\EventLogType.scala:207: possible missing interpolator: detected an interpolated expression [warn] implicit val fmtLogItemWrite: OWrites[EventInfo] = derived.owrites[EventInfo] [warn] ^ [error] D:\myproject\hg\myproject\app\models\events\EventLogType.scala:207: could not find Lazy implicit value of type julienrf.json.derived.DerivedOWrites[models.events.EventInfo] [error] implicit val fmtLogItemWrite: OWrites[EventInfo] = derived.owrites[EventInfo] [error] ^ [error] D:\myproject\hg\myproject\app\models\events\EventLogType.scala:213: could not find Lazy implicit value of type julienrf.json.derived.DerivedReads[models.events.EventInfo] [error] implicit val fmtLogItemRead: Reads[EventInfo] = derived.reads[EventInfo].orElse(Reads.pure(UnknownEventInfo())) [error] ^ [warn] one warning found [error] two errors found [error] (compile:compileIncremental) Compilation failed [error] Total time: 106 s, completed 2018.04.18. 8:09:52

EventLogType.zip

akitaylor avatar Apr 18 '18 08:04 akitaylor

I'm not sure. But firstly you can try seperating each sealed trait or class to their own files, i.e. not in one file.

Secondly you can try to make every implicit val formatter = oformt[A]() to implicit lazy val formatter = ...

And also the sequence of trait and object matters.

My problem is solved. But I don't have enough case classes to do the test.

WayneWang12 avatar Apr 18 '18 08:04 WayneWang12