Skip to content

GenCodec.materialize fails for Type Members and works for Type Parameters #67

Closed
@bgrochal

Description

@bgrochal

Please consider the following Type Parameter hierarchy:

sealed trait A[X] {
  def foo: X
}

object A {
  final case class First[Type : GenCodec](foo: Type) extends A[Type]
  object First {
    implicit def genCodec[Type : GenCodec]: GenCodec[First[Type]] = GenCodec.materialize
  }

  implicit def genCodec[T : GenCodec]: GenCodec[A[T]] = GenCodec.materialize
}

The code above compiles and works nicely. However, after turning the Type Parameter into the Type Member:

sealed trait A {
  type X
  def foo: X
}

object A {
  final case class First[Type : GenCodec](foo: Type) extends A { type X = Type }
  object First {
    implicit def genCodec[Type : GenCodec]: GenCodec[First[Type]] = GenCodec.materialize
  }

  implicit def genCodec[T : GenCodec]: GenCodec[A { type X = T }] = GenCodec.materialize
}

the compiler claims that Cannot automatically derive GenCodec for com.avsystem.yanush.components.shared.search.model.A{type X = T}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions