summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2011-05-05 15:27:53 +0000
committerLukas Rytz <lukas.rytz@epfl.ch>2011-05-05 15:27:53 +0000
commit1c0df8f97ec740eca56e82049f42d2ab2ec45d73 (patch)
tree18ee25208fb688965dd04a5a67f2c074c5948e10 /src
parent93b421779764614b81764325e4cc0d33328f7e3a (diff)
downloadscala-1c0df8f97ec740eca56e82049f42d2ab2ec45d73.tar.gz
scala-1c0df8f97ec740eca56e82049f42d2ab2ec45d73.tar.bz2
scala-1c0df8f97ec740eca56e82049f42d2ab2ec45d73.zip
fix #4502 and fix #4430. review by odersky.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
index e8c78dbab2..5b4a5b3c44 100644
--- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
@@ -271,16 +271,21 @@ trait NamesDefaults { self: Analyzer =>
})
(symPs, args).zipped map {
case ((sym, byName, repeated), arg) =>
- // resetAttrs required for #2290. given a block { val x = 1; x }, when wrapping into a function
- // () => { val x = 1; x }, the owner of symbol x must change (to the apply method of the function).
- val body = if (byName) blockTyper.typed(Function(List(), resetLocalAttrs(arg)))
- else if (repeated) arg match {
- case Typed(expr, Ident(tpnme.WILDCARD_STAR)) =>
- expr
- case _ =>
- val factory = Select(gen.mkAttributedRef(SeqModule), nme.apply)
- blockTyper.typed(Apply(factory, List(resetLocalAttrs(arg))))
- } else arg
+ val body =
+ if (byName) {
+ val res = blockTyper.typed(Function(List(), arg))
+ new ChangeOwnerTraverser(context.owner, res.symbol) traverse arg // fixes #2290
+ res
+ } else {
+ new ChangeOwnerTraverser(context.owner, sym) traverse arg // fixes #4502
+ if (repeated) arg match {
+ case Typed(expr, Ident(tpnme.WILDCARD_STAR)) =>
+ expr
+ case _ =>
+ val factory = Select(gen.mkAttributedRef(SeqModule), nme.apply)
+ blockTyper.typed(Apply(factory, List(resetLocalAttrs(arg))))
+ } else arg
+ }
atPos(body.pos)(ValDef(sym, body).setType(NoType))
}
}