Skip to content

Commit 4e57eca

Browse files
Merge pull request #7564 from dotty-staging/fix-#7477
Fix #7477: Use correct owner in eta expansion
2 parents af4aa19 + 4d37f36 commit 4e57eca

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import NameKinds.UniqueName
1414
import util.Spans._
1515
import collection.mutable
1616
import Trees._
17+
import Decorators._
1718

1819
/** A class that handles argument lifting. Argument lifting is needed in the following
1920
* scenarios:
@@ -47,7 +48,10 @@ abstract class Lifter {
4748
var liftedType = expr.tpe.widen
4849
if (liftedFlags.is(Method)) liftedType = ExprType(liftedType)
4950
val lifted = ctx.newSymbol(ctx.owner, name, liftedFlags | Synthetic, liftedType, coord = spanCoord(expr.span))
50-
defs += liftedDef(lifted, expr).withSpan(expr.span).setDefTree
51+
defs += liftedDef(lifted, expr)
52+
.withSpan(expr.span)
53+
.changeNonLocalOwners(lifted)
54+
.setDefTree
5155
ref(lifted.termRef).withSpan(expr.span.focus)
5256
}
5357

@@ -179,7 +183,7 @@ object EtaExpansion extends LiftImpure {
179183
* If `expr` has implicit function type, the arguments are passed with `given`.
180184
* E.g. for (1):
181185
*
182-
* { val xs = es; (x1, ..., xn) => expr given (x1, ..., xn) }
186+
* { val xs = es; (x1, ..., xn) => expr(given x1, ..., xn) }
183187
*
184188
* Case (3) applies if the method is curried, i.e. its result type is again a method
185189
* type. Case (2) applies if the expected arity of the function type `xarity` differs

tests/pos/i7477.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Test1 {
2+
def spawn(f: => Unit)(naming: Int = 4): Unit = ???
3+
def test(): Unit = spawn {
4+
val x: Int = 5
5+
x
6+
}()
7+
}
8+
package X {
9+
10+
import scala.concurrent._
11+
import scala.concurrent.duration._
12+
13+
import scala.concurrent.ExecutionContext.Implicits._
14+
15+
class Test1 {
16+
17+
def spawn[T](f: => T)(given ec:ExecutionContext, naming: Int = 3): Future[T] = ???
18+
19+
def await[T](f:Future[T], atMost: Duration = Duration.Inf)(given ec: ExecutionContext):T = ???
20+
21+
def test(): Unit = {
22+
val promiseToWait = Promise[Int]()
23+
val future1 = spawn{
24+
val x = await(promiseToWait.future)
25+
x+1
26+
}
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)