Skip to content

Commit a4c7e4a

Browse files
committed
fix: correctly auto import when there is a renamed symbol with the same name in scope
1 parent 284e7cc commit a4c7e4a

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

presentation-compiler/src/main/dotty/tools/pc/IndexedContext.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ sealed trait IndexedContext:
3636
Result.InScope
3737
// when all the conflicting symbols came from an old version of the file
3838
case Some(symbols) if symbols.nonEmpty && symbols.forall(_.isStale) => Result.Missing
39-
case Some(_) => Result.Conflict
40-
case None => Result.Missing
39+
case Some(symbols) if symbols.exists(rename(_).isEmpty) => Result.Conflict
40+
case _ => Result.Missing
4141
end lookupSym
4242

4343
/**

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

+31
Original file line numberDiff line numberDiff line change
@@ -1952,3 +1952,34 @@ class CompletionSuite extends BaseCompletionSuite:
19521952
"""TestEnum test
19531953
|""".stripMargin,
19541954
)
1955+
1956+
@Test def `i6477-1` =
1957+
checkEdit(
1958+
"""|package a
1959+
|import a.b.SomeClass as SC
1960+
|
1961+
|package b {
1962+
| class SomeClass
1963+
|}
1964+
|package c {
1965+
| class SomeClass
1966+
|}
1967+
|
1968+
|val bar: SC = ???
1969+
|val foo: SomeClass@@
1970+
|""".stripMargin,
1971+
"""|package a
1972+
|import a.b.SomeClass as SC
1973+
|import a.c.SomeClass
1974+
|
1975+
|package b {
1976+
| class SomeClass
1977+
|}
1978+
|package c {
1979+
| class SomeClass
1980+
|}
1981+
|
1982+
|val bar: SC = ???
1983+
|val foo: SomeClass
1984+
|""".stripMargin,
1985+
)

presentation-compiler/test/dotty/tools/pc/tests/edit/AutoImportsSuite.scala

+31
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,37 @@ class AutoImportsSuite extends BaseAutoImportsSuite:
405405
|""".stripMargin,
406406
)
407407

408+
@Test def `i6477` =
409+
checkEdit(
410+
"""|package a
411+
|import a.b.SomeClass as SC
412+
|
413+
|package b {
414+
| class SomeClass
415+
|}
416+
|package c {
417+
| class SomeClass
418+
|}
419+
|
420+
|val bar: SC = ???
421+
|val foo: <<SomeClass>> = ???
422+
|""".stripMargin,
423+
"""|package a
424+
|import a.b.SomeClass as SC
425+
|import a.c.SomeClass
426+
|
427+
|package b {
428+
| class SomeClass
429+
|}
430+
|package c {
431+
| class SomeClass
432+
|}
433+
|
434+
|val bar: SC = ???
435+
|val foo: SomeClass = ???
436+
|""".stripMargin
437+
)
438+
408439
private def ammoniteWrapper(code: String): String =
409440
// Vaguely looks like a scala file that Ammonite generates
410441
// from a sc file.

0 commit comments

Comments
 (0)