You should change the signature of method union
to
def union[U<:T](s : BoolSet[U]) : BoolSet[U]
or
def union[U>:T](s : BoolSet[U]) : BoolSet[T]
The reason is that type T
is contravariant in class BoolSet
, which mean BoolSet[A]
is a subtype of BoolSet[B]
if B <: A
.