E003: Deprecated With Operator
This warning is emitted when using with as a type operator to create compound types. In Scala 3, with has been deprecated in favor of intersection types using &.
Dotty introduces intersection types - & types. These replace the use of the with keyword. There are a few differences in semantics between intersection types and using with.
Example
trait A
trait B
def test(x: A with B): Unit = ()
Warning
-- [E003] Syntax Warning: example.scala:3:14 -----------------------------------
3 |def test(x: A with B): Unit = ()
| ^^^^
|with as a type operator has been deprecated; use & instead
|This construct can be rewritten automatically under -rewrite -source 3.4-migration.
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| Dotty introduces intersection types - & types. These replace the
| use of the with keyword. There are a few differences in
| semantics between intersection types and using with.
-----------------------------------------------------------------------------
Solution
// Use intersection type operator & instead of with
trait A
trait B
def test(x: A & B): Unit = ()
// The change also applies to type aliases and class definitions
trait Readable
trait Writable
type ReadWrite = Readable & Writable
class File extends Readable, Writable
In this article