Skip to content

Set[T].union methods and the like should accept Set[ST <: T]s as input. #9229

@scabug

Description

@scabug

Currently it's like

class Set[T]{
  def union(other:GenSet[T]):Set[T]
}

Which means that if B is a subclass of A,

val sa = Set(new A)
val sb = Set(new B)
val su:Set[A] = sa union sb

which is a simple request, results in a compile error. The Set[B] is invariant so it can't be taken as a Set[A] and union wont take Set[B]s for no reason I can imagine.
If, instead, the signature was

class Set[T]{
  def union[ST <: T](other:GenSet[ST]):Set[T]
}

everything would be golden.
The same criticism applies to the intersect method.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions