Skip to content

Commit 6c05c36

Browse files
authored
bugfix: No signature help for local methods (#18594)
2 parents 3e33f60 + 0fd88ee commit 6c05c36

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

compiler/src/dotty/tools/dotc/util/Signatures.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import core.NameKinds
1313
import core.Types._
1414
import core.Symbols.NoSymbol
1515
import interactive.Interactive
16+
import transform.SymUtils.isLocalToBlock
1617
import util.Spans.Span
1718
import reporting._
1819

@@ -178,7 +179,8 @@ object Signatures {
178179
(alternativeIndex, alternatives)
179180
case _ =>
180181
val funSymbol = fun.symbol
181-
val alternatives = funSymbol.owner.info.member(funSymbol.name).alternatives
182+
val alternatives = if funSymbol.isLocalToBlock then List(funSymbol.denot) else
183+
funSymbol.owner.info.member(funSymbol.name).alternatives
182184
val alternativeIndex = alternatives.map(_.symbol).indexOf(funSymbol) max 0
183185
(alternativeIndex, alternatives)
184186

presentation-compiler/test/dotty/tools/pc/tests/signaturehelp/SignatureHelpSuite.scala

+55
Original file line numberDiff line numberDiff line change
@@ -702,3 +702,58 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite:
702702
| ^^^^^^^^^^^
703703
|""".stripMargin
704704
)
705+
706+
@Test def `local-method` =
707+
check(
708+
"""
709+
|object Main {
710+
| def foo() = {
711+
| def deployment(
712+
| fst: String,
713+
| snd: Int = 1,
714+
| ): Option[Int] = ???
715+
| val abc = deployment(@@)
716+
| }
717+
|}
718+
|""".stripMargin,
719+
"""|deployment(fst: String, snd: Int): Option[Int]
720+
| ^^^^^^^^^^^
721+
|""".stripMargin,
722+
)
723+
724+
@Test def `local-method2` =
725+
check(
726+
"""
727+
|object Main {
728+
| val foo = {
729+
| def deployment(
730+
| fst: String,
731+
| snd: Int = 1,
732+
| ): Option[Int] = ???
733+
| deployment(@@)
734+
| }
735+
|}
736+
|""".stripMargin,
737+
"""|deployment(fst: String, snd: Int): Option[Int]
738+
| ^^^^^^^^^^^
739+
|""".stripMargin,
740+
)
741+
742+
@Test def `local-method3` =
743+
check(
744+
"""
745+
|object Main {
746+
| def foo = {
747+
| object a {
748+
| def apply(a: Int): Int = a
749+
| def apply(b: String): String = b
750+
| a(""@@)
751+
| }
752+
| }
753+
|}
754+
|""".stripMargin,
755+
"""|apply(b: String): String
756+
| ^^^^^^^^^
757+
|apply(a: Int): Int
758+
|""".stripMargin
759+
)

0 commit comments

Comments
 (0)