Skip to content

Commit

Permalink
Interactive: handle context bounds in extension construct workaround (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rochala authored Apr 17, 2024
1 parent 2176fe4 commit 2ba368d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
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)
)

0 comments on commit 2ba368d

Please sign in to comment.