Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of right associative extension methods across scaladoc and printers #20467

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
// - trailingUsing = List(`(using D)`)
// - rest = List(`(g: G)`, `(using H)`)
// we need to swap (rightTyParams ++ rightParam) with (leftParam ++ trailingUsing)
val (leftTyParams, rest1) = tree.paramss.span(isTypeParamClause)
val (leftTyParams, rest1) = tree.paramss match
case fst :: tail if isTypeParamClause(fst) => (List(fst), tail)
case other => (List(), other)
val (leadingUsing, rest2) = rest1.span(isUsingClause)
val (rightTyParams, rest3) = rest2.span(isTypeParamClause)
val (rightParam, rest4) = rest3.splitAt(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,9 @@ class ShortenedTypePrinter(
if gsym.is(Flags.ExtensionMethod) then
val filteredParams =
if gsym.name.isRightAssocOperatorName then
val (leadingTyParamss, rest1) = paramss.span(isTypeParamClause)
val (leadingTyParamss, rest1) = paramss match
case fst :: tail if isTypeParamClause(fst) => (List(fst), tail)
case other => (List(), other)
val (leadingUsing, rest2) = rest1.span(isUsingClause)
val (rightTyParamss, rest3) = rest2.span(isTypeParamClause)
val (rightParamss, rest4) = rest3.splitAt(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,3 +683,14 @@ class HoverTermSuite extends BaseHoverSuite:
|""".stripMargin,
"""yy: A{type T = Int}""".stripMargin.hover
)

@Test def `right-assoc-extension`: Unit =
check(
"""
|case class Wrap[+T](x: T)
|
|extension [T](a: T)
| def <<*@@:>>[U <: Tuple](b: Wrap[U]): Wrap[T *: U] = Wrap(a *: b.x)
|""".stripMargin,
"extension [T](a: T) def *:[U <: Tuple](b: Wrap[U]): Wrap[T *: U]".hover
)
7 changes: 7 additions & 0 deletions scaladoc-testcases/src/tests/rightAssocExtension.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package tests.rightAssocExtension

case class Wrap[+T](x: T)

extension [T](a: T)
def *:[U <: Tuple](b: Wrap[U]): Wrap[T *: U]
= Wrap(a *: b.x)
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ trait ClassLikeSupport:
if methodSymbol.isExtensionMethod && methodSymbol.isRightAssoc then
// Taken from RefinedPrinter.scala
// If you change the names of the clauses below, also change them in right-associative-extension-methods.md
val (leftTyParams, rest1) = memberInfo.paramLists.span(_.isType)
val (leftTyParams, rest1) = memberInfo.paramLists match
case fst :: tail if fst.isType => (List(fst), tail)
case other => (List(), other)
val (leadingUsing, rest2) = rest1.span(_.isUsing)
val (rightTyParams, rest3) = rest2.span(_.isType)
val (rightParam, rest4) = rest3.splitAt(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,5 @@ class InfixTypes extends SignatureTest("infixTypes", SignatureTest.all)
class ExtendsCall extends SignatureTest("extendsCall", SignatureTest.all)

class RefinedFunctionTypes extends SignatureTest("refinedFunctionTypes", SignatureTest.all)

class RightAssocExtension extends SignatureTest("rightAssocExtension", SignatureTest.all)
Loading