diff --git a/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala b/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala index 828b559a47ae..ec67c652cef0 100644 --- a/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala +++ b/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala @@ -27,9 +27,10 @@ object EtaExpansion { else { val name = UniqueName.fresh(prefix) val liftedType = fullyDefinedType(expr.tpe.widen, "lifted expression", expr.pos) - val sym = ctx.newSymbol(ctx.owner, name, EmptyFlags, liftedType, coord = positionCoord(expr.pos)) + val flags = expr.symbol.flags & Unused | Synthetic + val sym = ctx.newSymbol(ctx.owner, name, flags, liftedType, coord = positionCoord(expr.pos)) defs += ValDef(sym, expr) - ref(sym.termRef) + ref(sym.termRef).withPos(expr.pos) } /** Lift out common part of lhs tree taking part in an operator assignment such as diff --git a/tests/neg/unused-args-lifted.scala b/tests/neg/unused-args-lifted.scala new file mode 100644 index 000000000000..a7ef65fbb6cb --- /dev/null +++ b/tests/neg/unused-args-lifted.scala @@ -0,0 +1,16 @@ +object Test { + def foo(a: Int)(b: Int, c: Int) = 42 + unused def bar(i: Int): Int = { + println(1) + 42 + } + def baz: Int = { + println(1) + 2 + } + foo( + bar(baz) // error + )( + c = baz, b = baz // force all args to be lifted in vals befor the call + ) +} diff --git a/tests/pos/unused-args-lifted.scala b/tests/pos/unused-args-lifted.scala new file mode 100644 index 000000000000..24bda0859571 --- /dev/null +++ b/tests/pos/unused-args-lifted.scala @@ -0,0 +1,12 @@ +object Test { + def foo(unused a: Int)(b: Int, c: Int) = 42 + unused def bar(i: Int): Int = { + println(1) + 42 + } + def baz: Int = { + println(1) + 2 + } + foo(bar(baz))(c = baz, b = baz) // force all args to be lifted in vals befor the call +}