Are there any practical examples to differentiate between `with` in Scala 2 and `&` (Intersection Types) in Dotty?

I am trying to understand the difference between with in Scalac and & in dotty. The following example does demonstrate it

trait Base {
    def foo: Any
  }
  trait A extends Base {
    override def foo: Int = 1
  }
  trait B extends Base {
    override def foo: Any = "foo"
  }

def func(ab: A with B): Int = ab.foo // Compiles with Dotty (In dotty with is treat as &). But fails with Scalac

But in the above example object creation for type A with B is not possible. So there is no way to actually call func.
Is there any visible difference between & and with that a programmer can make use of?

FWIW, one can extend A with B, no problem.

class C extends A with B {
  override def foo: Int = 2
}
1 Like

ah, okay…I tried just the line class D extends A with B and gave up. Thanks you :slight_smile: