Skip to content

Commit 114be22

Browse files
Backport "Interactive: handle context bounds in extension construct workaround" to LTS (#21075)
Backports #20201 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents aaa2925 + 2bddf3b commit 114be22

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

compiler/src/dotty/tools/dotc/interactive/Completion.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,12 @@ object Completion:
186186
)(using Context): List[tpd.Tree] =
187187
untpdPath.collectFirst:
188188
case untpd.ExtMethods(paramss, _) =>
189-
val enclosingParam = paramss.flatten.find(_.span.contains(pos.span))
189+
val enclosingParam = paramss.flatten
190+
.find(_.span.contains(pos.span))
191+
.flatMap:
192+
case untpd.TypeDef(_, bounds: untpd.ContextBounds) => bounds.cxBounds.find(_.span.contains(pos.span))
193+
case other => Some(other)
194+
190195
enclosingParam.map: param =>
191196
ctx.typer.index(paramss.flatten)
192197
val typedEnclosingParam = ctx.typer.typed(param)

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala

+39
Original file line numberDiff line numberDiff line change
@@ -1838,3 +1838,42 @@ class CompletionSuite extends BaseCompletionSuite:
18381838
|""".stripMargin,
18391839
topLines = Some(3)
18401840
)
1841+
1842+
@Test def `context-bound-in-extension-construct` =
1843+
check(
1844+
"""
1845+
|object x {
1846+
| extension [T: Orde@@]
1847+
|}
1848+
|""".stripMargin,
1849+
"""Ordered[T] scala.math
1850+
|Ordering[T] scala.math
1851+
|""".stripMargin,
1852+
topLines = Some(2)
1853+
)
1854+
1855+
@Test def `context-bounds-in-extension-construct` =
1856+
check(
1857+
"""
1858+
|object x {
1859+
| extension [T: Ordering: Orde@@]
1860+
|}
1861+
|""".stripMargin,
1862+
"""Ordered[T] scala.math
1863+
|Ordering[T] scala.math
1864+
|""".stripMargin,
1865+
topLines = Some(2)
1866+
)
1867+
1868+
@Test def `type-bound-in-extension-construct` =
1869+
check(
1870+
"""
1871+
|object x {
1872+
| extension [T <: Orde@@]
1873+
|}
1874+
|""".stripMargin,
1875+
"""Ordered[T] scala.math
1876+
|Ordering[T] scala.math
1877+
|""".stripMargin,
1878+
topLines = Some(2)
1879+
)

0 commit comments

Comments
 (0)