Skip to content

Commit c25c8dd

Browse files
Backport "Fix handling of right associative extension methods across scaladoc and printers" to LTS (#21125)
Backports #20467 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents fd363fc + ebd1ee0 commit c25c8dd

File tree

6 files changed

+29
-3
lines changed

6 files changed

+29
-3
lines changed

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
936936
// - trailingUsing = List(`(using D)`)
937937
// - rest = List(`(g: G)`, `(using H)`)
938938
// we need to swap (rightTyParams ++ rightParam) with (leftParam ++ trailingUsing)
939-
val (leftTyParams, rest1) = tree.paramss.span(isTypeParamClause)
939+
val (leftTyParams, rest1) = tree.paramss match
940+
case fst :: tail if isTypeParamClause(fst) => (List(fst), tail)
941+
case other => (List(), other)
940942
val (leadingUsing, rest2) = rest1.span(isUsingClause)
941943
val (rightTyParams, rest3) = rest2.span(isTypeParamClause)
942944
val (rightParam, rest4) = rest3.splitAt(1)

presentation-compiler/src/main/dotty/tools/pc/printer/ShortenedTypePrinter.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,9 @@ class ShortenedTypePrinter(
419419
if gsym.is(Flags.ExtensionMethod) then
420420
val filteredParams =
421421
if gsym.name.isRightAssocOperatorName then
422-
val (leadingTyParamss, rest1) = paramss.span(isTypeParamClause)
422+
val (leadingTyParamss, rest1) = paramss match
423+
case fst :: tail if isTypeParamClause(fst) => (List(fst), tail)
424+
case other => (List(), other)
423425
val (leadingUsing, rest2) = rest1.span(isUsingClause)
424426
val (rightTyParamss, rest3) = rest2.span(isTypeParamClause)
425427
val (rightParamss, rest4) = rest3.splitAt(1)

presentation-compiler/test/dotty/tools/pc/tests/hover/HoverTermSuite.scala

+11
Original file line numberDiff line numberDiff line change
@@ -683,3 +683,14 @@ class HoverTermSuite extends BaseHoverSuite:
683683
|""".stripMargin,
684684
"""yy: A{type T = Int}""".stripMargin.hover
685685
)
686+
687+
@Test def `right-assoc-extension`: Unit =
688+
check(
689+
"""
690+
|case class Wrap[+T](x: T)
691+
|
692+
|extension [T](a: T)
693+
| def <<*@@:>>[U <: Tuple](b: Wrap[U]): Wrap[T *: U] = Wrap(a *: b.x)
694+
|""".stripMargin,
695+
"extension [T](a: T) def *:[U <: Tuple](b: Wrap[U]): Wrap[T *: U]".hover
696+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package tests.rightAssocExtension
2+
3+
case class Wrap[+T](x: T)
4+
5+
extension [T](a: T)
6+
def *:[U <: Tuple](b: Wrap[U]): Wrap[T *: U]
7+
= Wrap(a *: b.x)

scaladoc/src/dotty/tools/scaladoc/tasty/ClassLikeSupport.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,9 @@ trait ClassLikeSupport:
359359
if methodSymbol.isExtensionMethod && methodSymbol.isRightAssoc then
360360
// Taken from RefinedPrinter.scala
361361
// If you change the names of the clauses below, also change them in right-associative-extension-methods.md
362-
val (leftTyParams, rest1) = memberInfo.paramLists.span(_.isType)
362+
val (leftTyParams, rest1) = memberInfo.paramLists match
363+
case fst :: tail if fst.isType => (List(fst), tail)
364+
case other => (List(), other)
363365
val (leadingUsing, rest2) = rest1.span(_.isUsing)
364366
val (rightTyParams, rest3) = rest2.span(_.isType)
365367
val (rightParam, rest4) = rest3.splitAt(1)

scaladoc/test/dotty/tools/scaladoc/signatures/TranslatableSignaturesTestCases.scala

+2
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,5 @@ class MatchTypeTuple extends SignatureTest("matchTypeTuple", SignatureTest.all)
120120
class InfixTypes extends SignatureTest("infixTypes", SignatureTest.all)
121121

122122
class ExtendsCall extends SignatureTest("extendsCall", SignatureTest.all)
123+
124+
class RightAssocExtension extends SignatureTest("rightAssocExtension", SignatureTest.all)

0 commit comments

Comments
 (0)