-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Illegal cyclic reference error when abstract companion #67
Comments
Out of interest I looked at this, the macro desugars to: package object some {
type MyInt = MyInt.Type
object MyInt extends AbstractObjectCompanion[MyInt] {
type Base = Any { type __MyInt__newtype }
abstract trait Tag extends Any
type Type <: Base with Tag
}
} (ignoring other details) which is just cyclic. I guess Base/Tag could be obfuscated a bit ( 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.. |
That begs the question, have you tried the following? abstract class AbstractObjectCompanion {
type Type
def apply(src: Int): Type
implicit class Ops(t: Type) {
def print = t.toString
}
} |
Sorry to bump this old issue, but just ran into this exact situation. I want to extract some boilerplate
@newtype final case class Foo private (x: String)
object Foo extends MyBase(...)
abstract class MyBase(...) {
type Type
def fromString(s: String)(implicit ev: Coercible[String, Type]): Either[String, Type] =
alphanumeric(s).map(_.coerce[Type])
} (using abstract class here to pass additional ctor parameters needed for other things) This gives me:
as expected. Leaving this here for anyone who would run into this issue... |
That's the whole point, if you leave it abstract |
D'oh! Of course :) Haha this is even better! Thanks @joroKr21! |
I suppose the companion objects aren't working
as expected
when they have a type hierarchy.Consider a simple example:
... does not compile:
But it compiles without
@newtype
OR withoutAbstractObjectCompanion.
The text was updated successfully, but these errors were encountered: