Scala3 extension drops colon's right-associativity

The following produces different results depending on which line is un-commented.

//  implicit class C(i: Int):  //extension the old way
//  extension (i: Int)         //extension the new way
      def @:(arg: Int):Unit = println(s"$i.@:($arg)")

  44 @: 7

Is this by design? I haven’t found it documented.

1 Like

It appears to be by design. Note however that the operator remains right-associative. I.e. 1 @: 2 @: 3 is evaluated as (1 @: (2 @: 3)).

There’s some talk about right associative extension methods here under the “Operators” header. And more details here.

I guess they did it this way because it’s more intuitive that the “receiver” is always the argument on the left. But I’m not sure they succeeded, cause now you have the weird “parameter swapping” which can cause issues with dependent parameters, and the discrepancy with right-associative methods on classes.