Skip to content

Commit 331f06f

Browse files
committed
Fix unused lifted args before unused checks
Also fix position of lifted arg reference tree.
1 parent 5b618dd commit 331f06f

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ object EtaExpansion {
2727
else {
2828
val name = UniqueName.fresh(prefix)
2929
val liftedType = fullyDefinedType(expr.tpe.widen, "lifted expression", expr.pos)
30-
val sym = ctx.newSymbol(ctx.owner, name, EmptyFlags, liftedType, coord = positionCoord(expr.pos))
30+
val flags = expr.symbol.flags & Unused | Synthetic
31+
val sym = ctx.newSymbol(ctx.owner, name, flags, liftedType, coord = positionCoord(expr.pos))
3132
defs += ValDef(sym, expr)
32-
ref(sym.termRef)
33+
ref(sym.termRef).withPos(expr.pos)
3334
}
3435

3536
/** Lift out common part of lhs tree taking part in an operator assignment such as

tests/neg/unused-args-lifted.scala

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
object Test {
2+
def foo(a: Int)(b: Int, c: Int) = 42
3+
unused def bar(i: Int): Int = {
4+
println(1)
5+
42
6+
}
7+
def baz: Int = {
8+
println(1)
9+
2
10+
}
11+
foo(
12+
bar(baz) // error
13+
)(
14+
c = baz, b = baz // force all args to be lifted in vals befor the call
15+
)
16+
}

tests/pos/unused-args-lifted.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object Test {
2+
def foo(unused a: Int)(b: Int, c: Int) = 42
3+
unused def bar(i: Int): Int = {
4+
println(1)
5+
42
6+
}
7+
def baz: Int = {
8+
println(1)
9+
2
10+
}
11+
foo(bar(baz))(c = baz, b = baz) // force all args to be lifted in vals befor the call
12+
}

0 commit comments

Comments
 (0)