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

Interactive: handle context bounds in extension construct workaround #20201

Merged
merged 1 commit into from
Apr 17, 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
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/interactive/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,12 @@ object Completion:
)(using Context): List[tpd.Tree] =
untpdPath.collectFirst:
case untpd.ExtMethods(paramss, _) =>
val enclosingParam = paramss.flatten.find(_.span.contains(pos.span))
val enclosingParam = paramss.flatten
.find(_.span.contains(pos.span))
.flatMap:
case untpd.TypeDef(_, bounds: untpd.ContextBounds) => bounds.cxBounds.find(_.span.contains(pos.span))
case other => Some(other)

enclosingParam.map: param =>
ctx.typer.index(paramss.flatten)
val typedEnclosingParam = ctx.typer.typed(param)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1838,3 +1838,42 @@ class CompletionSuite extends BaseCompletionSuite:
|""".stripMargin,
topLines = Some(3)
)

@Test def `context-bound-in-extension-construct` =
check(
"""
|object x {
| extension [T: Orde@@]
|}
|""".stripMargin,
"""Ordered[T] scala.math
|Ordering[T] scala.math
|""".stripMargin,
topLines = Some(2)
)

@Test def `context-bounds-in-extension-construct` =
check(
"""
|object x {
| extension [T: Ordering: Orde@@]
|}
|""".stripMargin,
"""Ordered[T] scala.math
|Ordering[T] scala.math
|""".stripMargin,
topLines = Some(2)
)

@Test def `type-bound-in-extension-construct` =
check(
"""
|object x {
| extension [T <: Orde@@]
|}
|""".stripMargin,
"""Ordered[T] scala.math
|Ordering[T] scala.math
|""".stripMargin,
topLines = Some(2)
)