magnolia
magnolia copied to clipboard
Classes with a companion object and private constructor are not supported
Magnolia can not derive typeclasses instances for the following class:
class PrivateClass private (val value: Long) extends AnyVal
object PrivateClass {
def apply(l: Long) = new PrivateClass(l)
}
The derived instance will contain something along the line of:
new PrivateClass(makeParam(parameters$macro$262(0)).asInstanceOf[Long]);
Which will fail to compile with the following error:
[error] constructor PrivateClass in class PrivateClass cannot be accessed in <$anon: magnolia.CaseClass[MyTypeclass.Typeclass, PrivateClass]>
[error] MyTypeclass.gen[PrivateClass]
[error] ^
I still have the same problem as described in https://github.com/propensive/magnolia/pull/139#issuecomment-422867151:
the following code:
case class Private private(i: Int, l: Long)
object Private {
val codecOfPrivate: ... = ...
}
cannot compile:
magnolia: could not infer package.Typeclass for type Private
Should we create another issue for this?
To fix that we could just replace all calls to new CaseClass(..params) to CaseClass(..params).
Though the apply method would have to match the signature.
So not sure what is the use case of this?