Use `,` instead of `with` when there are more than one trait?

When there are more than one trait to be mixed in, currently we need chain with with, eg:

new GraphStageLogic(shape) with OutHandler with InHandler 

What I expected is

new GraphStageLogic(shape) with OutHandler ,InHandler 

If we don’t need the special trait mixin handing.

It’s quit long for Scala 3

3 Likes

Actually, we could even allow it when the order matters,
Since extends A, B is always valid, even in that case (iirc)

2 Likes

Why do we have two different keywords (extends and with) anyway? The use of them seems always forced.

2 Likes

Isn’t the idea that in Scala 3, & will replace with? So you would do A extends B & C

1 Like

Not exactly, the details are a bit murky, but this is the general idea:

with is used for two different things in Scala 2:

  • C extends A with B: C has all the members of B, plus the unshadowed members of C
  • type C = A with B: again, C has all the members of B, plus the unshadowed some members of C

Notably, A with B is not the same as B with A

But this is not what & does (and with in Scala 3 is an alias of &):

  • C extends A, B: C has all the members of B, plus the unshadowed members of C
  • type C = A & B: C has all the members of both A and B

Notably, A & B is the same as B & A

See for example

class linearisation spec

3 Likes