trait Base
class A extends Base
class B extends Base
I want to implement infix + in A() + B() as an alias for Set(a, b)
trait Base:
infix def +[X <: Base](x: X) =
Set(this, x)
but it fails
val set = A() + B()
def f(set: Set[A | B]) = {}
f(set)
// ^
// Found: (Playground.set : Set[? >: Playground.B <: Playground.A | Playground.B])
// Required: Set[Playground.A | Playground.B]
the this.type behavior is breaking it, resulting in this irritating ? >: instead of simply B.
It works if I do prefix notation (useless to me though)
def `+`[T <: Base, K <: Base](t: T, k: K): Set[T | K] = Set(t, k)
val set = `+`(A(), B())
def f(set: Set[A | B]) = {}
f(set)