You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importscala.compiletime.deferredtraitMyCodec[E]
objectauto {
traitCompanionEssentials[E] {
givenMyCodec[E] = deferred
}
}
importauto.CompanionEssentialscaseclassPerson(name: String, age: Int)
objectPersonextendsCompanionEssentials[Person]
// deferred given implemented as:// override final lazy given val given_MyCodec_E: MyCodec[Person] =// Person.given_MyCodec_E
Output
Due to module class Person being in the implicit scope of Person, the compiler resolves the deferred given to its unimplemented self resulting in infinite recursion. This happens regardless of presence of a valid given in scope or not.
Expectation
The compiler should detect the cycle and exclude Person.given_MyCodec_E as a viable candidate, and produce an error if the deferred given couldn't be synthesized from other candidates in scope.
Workaround
The infinite recursion problem can be avoided by explicitly importing the relevant givens (which is probably what you should be doing in the first place):
objectauto {
traitCompanionEssentials[E] {
givenMyCodec[E] = deferred
}
given [E] =>MyCodec[E] =newMyCodec[E]{}
}
importauto.{CompanionEssentials, given}
caseclassPerson(name: String, age: Int)
objectPersonextendsCompanionEssentials[Person]
// deferred given implemented as:// override final lazy given val given_MyCodec_E: MyCodec[Person] =// auto.given_MyCodec_E[Person]
The text was updated successfully, but these errors were encountered:
It's interesting that it doesn't trigger in CheckLoopingImplicits, as the RHS is derived from the enclosing environment. The explicit definition warns as normal.
Compiler version
3.6.3
Minimized code
Output
Due to
module class Person
being in the implicit scope ofPerson
, the compiler resolves the deferred given to its unimplemented self resulting in infinite recursion. This happens regardless of presence of a valid given in scope or not.Expectation
The compiler should detect the cycle and exclude
Person.given_MyCodec_E
as a viable candidate, and produce an error if the deferred given couldn't be synthesized from other candidates in scope.Workaround
The infinite recursion problem can be avoided by explicitly importing the relevant
given
s (which is probably what you should be doing in the first place):The text was updated successfully, but these errors were encountered: