Skip to content

Cannot use derives when typeclasses have the same name #17328

Open
@kyri-petrou

Description

@kyri-petrou

Compiler version

3.2.2, 3.3.0-RC4

Minimized code

trait Foo[A]
object Foo:
  trait Codec[A] extends Foo[A]
  object Codec:
    inline def derived[A]: Codec[A] = ???
end Foo

trait Bar[A]
object Bar:
  trait Codec[A] extends Bar[A]
  object Codec:
    inline def derived[A]: Codec[A] = ???
end Bar

final case class FooBar() derives Foo.Codec, Bar.Codec

Output

The code above fails to compile with the following error:

[error] 15 |final case class FooBar() derives Foo.Codec, Bar.Codec
[error]    |                                             ^^^^^^^^^
[error]    |                               duplicate type class derivation for Codec

Expectation

I'm not sure if this is a bug or the intended operation. A workaround is to alias one of the Codecs. e.g., the following works:

type BarCodec[A] = Bar.Codec[A]
final case class FooBar() derives Foo.Codec, BarCodec

If this is the intended operation, would it make sense for the compiler to auto-generate the alias, or if that's not possible, provide the workaround in the error description?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions