Skip to content

Commit

Permalink
Fix unused lifted args before unused checks
Browse files Browse the repository at this point in the history
Also fix position of lifted arg reference tree.
  • Loading branch information
nicolasstucki committed Oct 27, 2017
1 parent faea603 commit 975b36f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/neg/unused-args-lifted.scala
Original file line number Diff line number Diff line change
@@ -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
)
}
12 changes: 12 additions & 0 deletions tests/pos/unused-args-lifted.scala
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 975b36f

Please sign in to comment.