Skip to content

Commit d6b4c56

Browse files
committed
Make sure that prefixes are not accidentally erased
1 parent bd4b6dd commit d6b4c56

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

compiler/src/dotty/tools/dotc/transform/UnusedRefs.scala

+6-8
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,13 @@ class UnusedRefs extends MiniPhase {
4545
tree.tpe.widen match {
4646
case _: MethodOrPoly => tree // Do the transformation higher in the tree if needed
4747
case _ =>
48-
tree match {
49-
case _: RefTree | _: TypeApply => defaultValue(tree.tpe)
50-
case Apply(_ , args) =>
51-
def allArgs(t: Tree, acc: List[Tree]): List[Tree] = t match {
52-
case Apply(fun, args) => allArgs(fun, args ::: acc)
53-
case _ => acc
54-
}
55-
seq(allArgs(tree, Nil), defaultValue(tree.tpe))
48+
def qualAndArgs(t: Tree, acc: List[Tree]): List[Tree] = t match {
49+
case TypeApply(fun, _) => qualAndArgs(fun, acc)
50+
case Apply(fun, args) => qualAndArgs(fun, args ::: acc)
51+
case Select(qual, _) => qual :: acc
52+
case _ => acc
5653
}
54+
seq(qualAndArgs(tree, Nil), defaultValue(tree.tpe))
5755
}
5856
}
5957
}

tests/run/unused-select-prefix.check

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Test0
2+
Test1
3+
Test2
4+
Test3

tests/run/unused-select-prefix.scala

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
object Test {
2+
3+
def main(args: Array[String]): Unit = {
4+
{
5+
println("Test0")
6+
Test
7+
}.foo0
8+
9+
{
10+
println("Test1")
11+
Test
12+
}.foo1()
13+
14+
{
15+
println("Test2")
16+
Test
17+
}.foo2[Int]
18+
19+
{
20+
println("Test3")
21+
Test
22+
}.foo3[Int]()
23+
24+
()
25+
}
26+
27+
unused def foo0: Int = 0
28+
unused def foo1(): Int = 1
29+
unused def foo2[T]: Int = 2
30+
unused def foo3[T](): Int = 3
31+
32+
}

0 commit comments

Comments
 (0)