Closed
Description
I am not using dotty yet and merely read the doc about union types. Might be this is already supported. The idea is that the compiler does the dynamic dispatch if a method is called on a union type. For instance:
trait A { def foo(){} }
trait B { def foo(){} }
object Test {
def test(fooable: A | B) {
fooable.foo()
}
}
Would expand to:
object Test {
def test(fooable: A | B) {
fooable match {
case a: A => a.foo()
case b: B => b.foo()
}
}
}
This would also go well in combination with structural types:
def test(fooable: A | B | { def foo(): Unit }) {
fooable.foo()
}
Would expand to something like:
object Test {
def test(fooable: A | B | { def foo(): Unit }): Unit = {
fooable match {
case a: A => a.foo()
case b: B => b.foo()
case x => x.asInstanceOf[{ def foo(): Unit }].foo()
}
}
Metadata
Metadata
Assignees
Labels
No labels