Skip to content

Fix #7477: Use correct owner in eta expansion #7564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import NameKinds.UniqueName
import util.Spans._
import collection.mutable
import Trees._
import Decorators._

/** A class that handles argument lifting. Argument lifting is needed in the following
* scenarios:
Expand Down Expand Up @@ -47,7 +48,10 @@ abstract class Lifter {
var liftedType = expr.tpe.widen
if (liftedFlags.is(Method)) liftedType = ExprType(liftedType)
val lifted = ctx.newSymbol(ctx.owner, name, liftedFlags | Synthetic, liftedType, coord = spanCoord(expr.span))
defs += liftedDef(lifted, expr).withSpan(expr.span).setDefTree
defs += liftedDef(lifted, expr)
.withSpan(expr.span)
.changeNonLocalOwners(lifted)
.setDefTree
ref(lifted.termRef).withSpan(expr.span.focus)
}

Expand Down Expand Up @@ -179,7 +183,7 @@ object EtaExpansion extends LiftImpure {
* If `expr` has implicit function type, the arguments are passed with `given`.
* E.g. for (1):
*
* { val xs = es; (x1, ..., xn) => expr given (x1, ..., xn) }
* { val xs = es; (x1, ..., xn) => expr(given x1, ..., xn) }
*
* Case (3) applies if the method is curried, i.e. its result type is again a method
* type. Case (2) applies if the expected arity of the function type `xarity` differs
Expand Down
29 changes: 29 additions & 0 deletions tests/pos/i7477.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Test1 {
def spawn(f: => Unit)(naming: Int = 4): Unit = ???
def test(): Unit = spawn {
val x: Int = 5
x
}()
}
package X {

import scala.concurrent._
import scala.concurrent.duration._

import scala.concurrent.ExecutionContext.Implicits._

class Test1 {

def spawn[T](f: => T)(given ec:ExecutionContext, naming: Int = 3): Future[T] = ???

def await[T](f:Future[T], atMost: Duration = Duration.Inf)(given ec: ExecutionContext):T = ???

def test(): Unit = {
val promiseToWait = Promise[Int]()
val future1 = spawn{
val x = await(promiseToWait.future)
x+1
}
}
}
}