Illegal cyclic reference error when abstract companion
See original GitHub issueI suppose the companion objects aren’t working as expected
when they have a type hierarchy.
Consider a simple example:
- I have some re-usable companion:
abstract class AbstractObjectCompanion[T] {
def apply(src: Int): T
implicit class Ops(t: T) {
def print = t.toString
}
}
- And its implementation here:
import io.estatico.newtype.macros.newtype
package object some {
@newtype class MyInt(val i: Int)
object MyInt extends AbstractObjectCompanion[MyInt] {
override def apply(src: Int): MyInt = new MyInt(src)
}
}
… does not compile:
illegal cyclic reference involving type MyInt
object MyInt extends AbstractObjectCompanion[MyInt] {
But it compiles without @newtype
OR without AbstractObjectCompanion.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Issues · estatico/scala-newtype - GitHub
Illegal cyclic reference error when abstract companion. #67 opened on Feb 15, 2021 by dmitry-worker · 5. No TypeTag available for newtypes.
Read more >Explanation for "illegal cyclic reference" involving implicits
What is the compiler tying to do/infer/resolve that involves an illegal cylce? Bonus points for a valid way to implement these implicit classes....
Read more >scalaz/scalaz-plugin - Gitter
_ abstract class AnnotatedClassTransformer(predicate: Symbol => Boolean, ... Symbols$CyclicReference: illegal cyclic reference involving method copy: while ...
Read more >[SOLVED] Objects implementing traits - Question - Scala Users
I have there that problem where a Companion Object extends a trait and it ... Error:(10, 56) illegal cyclic reference involving object Store ......
Read more >Web service error codes (Microsoft Dataverse) - Power Apps
Message: Field {0} cannot be used in calculated field {1} because it would create a circular reference. 0x8006043a -2147089350, Name: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
D’oh! Of course 😃 Haha this is even better! Thanks @joroKr21!
Out of interest I looked at this, the macro desugars to:
(ignoring other details) which is just cyclic. I guess Base/Tag could be obfuscated a bit (
__MyInt__
prefixed) and moved out, and just define the external Type.I’m guessing that the compiler must have ways to deal with this when dealing with companion classes and companion objects in a cyclical relationship…