Skip to content

Commit 43a0fc5

Browse files
dos65tgodzik
authored andcommitted
pc: completions - do not add [] for ... derives TC@@ (scala#23811)
Currently it incorectly adds completion members with square brackets. Exmaple: ```scala class X derives CanEqua@@ // returns `CanEqual[@@]` and `CanEqual` // should return only `CanEqual` ``` [Cherry-picked 17f1803]
1 parent fae0cc4 commit 43a0fc5

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)