Skip to content

Can't extend Edges in case class in scala 3 #300

Closed
@TomLous

Description

@TomLous

For the 2.0.0 release with Scala 3.3.1

I'm aware that the library was build for 2.13, but I'm using it with scala 3 and seems to work for the most part

The main issue was with using a case class for creating a labeled Edge

private case class LocationEdge(source: String, target: String, label: Direction) extends LDiEdge[String, Direction]

Which gives the error:

error overriding method _1 in trait AnyDiEdge of type => String;
method _1 of type => String cannot override final member method _1 in trait AnyDiEdge
..
error overriding method _2 in trait AnyDiEdge of type => String;
method _2 of type => String cannot override final member method _2 in trait AnyDiEdge

The workaround was to use a normal class, like

 private case class LocationEdge(override val source: String, override val target: String, override val label: Direction) extends LDiEdge[String, Direction]:
    override def equals(obj: Any): Boolean =
      super.equals(obj) && obj.isInstanceOf[LocationEdge] && obj.asInstanceOf[LocationEdge].label == label

But that also meant I had to override the equals method if I didn't want Edges with the same spurce/target but different labels to be deduplicated

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions