Skip to content

Commit 4b8bd3f

Browse files
authored
Merge pull request #571 from scala/backport-lts-3.3-23811
Backport "pc: completions - do not add `[]` for `... derives TC@@`" to 3.3 LTS
2 parents d42ab25 + 71a45a9 commit 4b8bd3f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,15 @@ class Completions(
7474
case tpe :: (appl: AppliedTypeTree) :: _ if appl.tpt == tpe => false
7575
case sel :: (funSel @ Select(fun, name)) :: (appl: GenericApply) :: _
7676
if appl.fun == funSel && sel == fun => false
77-
case _ => true)
77+
case _ => true) &&
78+
(adjustedPath match
79+
/* In case of `class X derives TC@@` we shouldn't add `[]`
80+
*/
81+
case Ident(_) :: (templ: untpd.DerivingTemplate) :: _ =>
82+
val pos = completionPos.toSourcePosition
83+
!templ.derived.exists(_.sourcePos.contains(pos))
84+
case _ => true
85+
)
7886

7987
private lazy val isNew: Boolean = Completion.isInNewContext(adjustedPath)
8088

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,3 +2238,11 @@ class CompletionSuite extends BaseCompletionSuite:
22382238
|""".stripMargin,
22392239
"asTerm: Term"
22402240
)
2241+
2242+
@Test def `derives-no-square-brackets` =
2243+
check(
2244+
"""
2245+
|case class Miau(y: Int) derives Ordering, CanEqu@@
2246+
|""".stripMargin,
2247+
"CanEqual scala"
2248+
)

0 commit comments

Comments
 (0)