E003: Deprecated With Operator
This message is emitted when using with as a type operator to create compound types. In Scala 3, with has been replaced by intersection types using &: it was deprecated since 3.4 and is an error since 3.10. In the 3.4 to 3.9 source versions it is still reported as a warning.
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 = ()
Error
-- [E003] Syntax Error: 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