Description
With the way right associative extension methods are desugared (https://docs.scala-lang.org/scala3/reference/contextual/right-associative-extension-methods.html), some different methods end up with the same desugared form.
Both of those methods:
extension (x: X) def +:: [T](y: Y)
extension [T](x: X) def +:: (y: Y)
are desugared to:
<extension> def +:: [T](y: Y)(x: X)
It's important that the desugaring is reversible for some tools in the ecosystem, to display correct signature.
Scaladoc hacked solved this by sorting the parameters by their source positions, but the problem remains in ShortenedTypePrinter
and RefinedPrinter
:
scala3/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Lines 987 to 1016 in c61897d
This bug in ShortenedTypePrinter
can be seen in Metals:
My question is, can we add some additional information in desugar so that the desugared form can be reversed easily to original signature?
This could be a flag added to type parameters that are next to extension
keyword, maybe the third flag here (?):
scala3/compiler/src/dotty/tools/dotc/core/Flags.scala
Lines 320 to 321 in c61897d
Or this could be an annotation attached to such type params:
extension [T](x: X) def +:: (y: Y)
-> <extension> def +:: [@extensionTypeParam T](y: Y)(x: X)
extension (x: X) def +:: [T](y: Y)
-> <extension> def +:: [T](y: Y)(x: X)