Skip to content

Commit 690cc81

Browse files
Backport "bugfix: Completions for extension methods with name conflict" to LTS (#20793)
Backports #19225 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents fcd7562 + 773daca commit 690cc81

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ class CompletionProvider(
248248
mkItem(
249249
"{" + sym.fullNameBackticked + completionTextSuffix + "}"
250250
)
251+
case _ if v.isExtensionMethod =>
252+
mkItem(
253+
ident.backticked(backtickSoftKeyword) + completionTextSuffix
254+
)
251255
case _ =>
252256
mkItem(
253257
sym.fullNameBackticked(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ object CompletionValue:
6464
def symbol: Symbol
6565
def isFromWorkspace: Boolean = false
6666
override def completionItemDataKind = CompletionItemData.None
67+
def isExtensionMethod: Boolean = false
6768

6869
override def completionData(
6970
buildTargetIdentifier: String
@@ -153,6 +154,7 @@ object CompletionValue:
153154
override def completionItemKind(using Context): CompletionItemKind =
154155
CompletionItemKind.Method
155156
override def completionItemDataKind: Integer = CompletionSource.ExtensionKind.ordinal
157+
override def isExtensionMethod: Boolean = true
156158
override def description(printer: ShortenedTypePrinter)(using Context): String =
157159
s"${printer.completionSymbol(symbol)} (extension)"
158160

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,35 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
174174
|increment2: Int (extension)
175175
|""".stripMargin
176176
)
177+
178+
@Test def `name-conflict` =
179+
checkEdit(
180+
"""
181+
|package example
182+
|
183+
|import example.enrichments.*
184+
|
185+
|object enrichments:
186+
| extension (num: Int)
187+
| def plus(other: Int): Int = num + other
188+
|
189+
|def main = {
190+
| val plus = 100.plus(19)
191+
| val y = 19.pl@@
192+
|}
193+
|""".stripMargin,
194+
"""
195+
|package example
196+
|
197+
|import example.enrichments.*
198+
|
199+
|object enrichments:
200+
| extension (num: Int)
201+
| def plus(other: Int): Int = num + other
202+
|
203+
|def main = {
204+
| val plus = 100.plus(19)
205+
| val y = 19.plus($0)
206+
|}
207+
|""".stripMargin
208+
)

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,3 +825,27 @@ class CompletionWorkspaceSuite extends BaseCompletionSuite:
825825
|MyType - demo.other""".stripMargin,
826826
)
827827

828+
@Test def `method-name-conflict` =
829+
checkEdit(
830+
"""|package demo
831+
|
832+
|object O {
833+
| def mmmm(x: Int) = x + 3
834+
| class Test {
835+
| val mmmm = "abc"
836+
| val foo = mmmm@@
837+
| }
838+
|}
839+
|""".stripMargin,
840+
"""|package demo
841+
|
842+
|object O {
843+
| def mmmm(x: Int) = x + 3
844+
| class Test {
845+
| val mmmm = "abc"
846+
| val foo = demo.O.mmmm($0)
847+
| }
848+
|}
849+
|""".stripMargin,
850+
filter = _.contains("mmmm(x: Int)")
851+
)

0 commit comments

Comments
 (0)