Question: desugaring of right associative extenstion methods #22170
Labels
area:desugar
Desugaring happens after parsing but before typing, see desugar.scala
area:extension-methods
itype:question
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:
are desugared to:
It's important that the desugaring is reversible for some tools in the ecosystem, to display correct signature.
Scaladoc
hackedsolved this by sorting the parameters by their source positions, but the problem remains inShortenedTypePrinter
andRefinedPrinter
:scala3/presentation-compiler/src/main/dotty/tools/pc/printer/ShortenedTypePrinter.scala
Lines 425 to 436 in c61897d
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)
The text was updated successfully, but these errors were encountered: