Skip to content

Commit 2333135

Browse files
KacperFKorbankasiaMarek
authored andcommitted
fix: Only fallback to the definition of a synthetic valdef if it is zero extent (scala#22551)
closes scalameta/metals#7038 closes scalameta/metals#7191 fixes the reproduction issue from scala#22217 Co-authored-by: Katarzyna Marek <26606662+kasiaMarek@users.noreply.github.com> [Cherry-picked 37206cc]
1 parent 912fd2b commit 2333135

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ class CompletionProvider(
9999
* 4| $1$.sliding@@[Int](size, step)
100100
*
101101
*/
102-
if qual.symbol.is(Flags.Synthetic) && qual.symbol.name.isInstanceOf[DerivedName] =>
102+
if qual.symbol.is(Flags.Synthetic) && qual.span.isZeroExtent && qual.symbol.name.isInstanceOf[DerivedName] =>
103103
qual.symbol.defTree match
104-
case valdef: ValDef => Select(valdef.rhs, name) :: tail
104+
case valdef: ValDef if !valdef.rhs.isEmpty => Select(valdef.rhs, name) :: tail
105105
case _ => tpdPath0
106106
case _ => tpdPath0
107107

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,3 +2134,14 @@ class CompletionSuite extends BaseCompletionSuite:
21342134
"""|build: Unit
21352135
|""".stripMargin,
21362136
)
2137+
2138+
@Test def i7191 =
2139+
check(
2140+
"""|val x = Some(3).map(_.@@)
2141+
|""".stripMargin,
2142+
"""|!=(x: Byte): Boolean
2143+
|!=(x: Char): Boolean
2144+
|!=(x: Double): Boolean
2145+
|""".stripMargin,
2146+
topLines = Some(3)
2147+
)

0 commit comments

Comments
 (0)