summaryrefslogtreecommitdiff
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
parent93b421779764614b81764325e4cc0d33328f7e3a (diff)
downloadscala-1c0df8f97ec740eca56e82049f42d2ab2ec45d73.tar.gz
scala-1c0df8f97ec740eca56e82049f42d2ab2ec45d73.tar.bz2
scala-1c0df8f97ec740eca56e82049f42d2ab2ec45d73.zip
fix #4502 and fix #4430. review by odersky.
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala25
-rw-r--r--test/files/pos/t4430.scala11
-rw-r--r--test/files/pos/t4502.scala12
3 files changed, 38 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))
}
}
diff --git a/test/files/pos/t4430.scala b/test/files/pos/t4430.scala
new file mode 100644
index 0000000000..746ecb271e
--- /dev/null
+++ b/test/files/pos/t4430.scala
@@ -0,0 +1,11 @@
+class Crash {
+ def S(op: => Double) = 0
+ def A(a: Int, b: Int) = 0
+
+ val t = 0
+
+ val q = A(
+ b = S { val xxx = t ; 42 },
+ a = 0
+ )
+}
diff --git a/test/files/pos/t4502.scala b/test/files/pos/t4502.scala
new file mode 100644
index 0000000000..ed7d3d0557
--- /dev/null
+++ b/test/files/pos/t4502.scala
@@ -0,0 +1,12 @@
+class T {
+ def send(o: Any, d: Int = 10) { }
+
+ def c(f: => Any) { }
+
+ def f() {
+ var a = this
+ a.send(
+ c(a.send(()))
+ )
+ }
+}