Indent syntax for extension

I am liking the new syntax so far, but only one thing feels odd about it.
Just wondering if optional braces syntax for extension should allow for colon like the following. It feels odd compared to the rest of the language when using optional braces. Apologies if this was discussed before. With that said it’s not a huge issue.

 extension [A](src: RedisStreamCodec[A]):
    def doSomething: Int = 1
2 Likes

probably this is where it first was defined this way: Unified extension methods by odersky · Pull Request #9255 · lampepfl/dotty · GitHub

before this PR, extension NameOps on (name: Name): ... introduced a new given instance with a unique class, but now collective extensions desugar to methods in their surrounding scope. I think this choice was made deliberately to say “there is no new scope being introduced here” visually (even though there still exists the variant with braces)

1 Like

I also have trouble remembering what the correct syntax for extension methods is, it feels really unintuitive to have a indent bloc that’s not after “something special” (then, match, :, …)

I’m also daunted and confused by Scala 3 syntax, but I like

extension thing def f

is simple and can be extended by

extension thing
  def f
  def g

I feel sorry for anyone using other syntax that requires colon or with.

AFAIK, the pr mentioned above has a replacement for this kind of “one line extension” so the semicolon should not disturb you in that case.

What do you mean by thing ? Because for example extension Int ... doesn’t work, because you might need info on which Int it is, so you need at least x: Int, but then you have two options:

extension x: Int
  def f
  def g
// or:
extension (x: Int)
  def f
  def g

The first looks odd, and the second is the one actually used !
With only one clause, I agree this looks better, but when you start getting type and using clauses, it starts being messy (and : makes more sense for me)