summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2012-04-26 15:29:07 +0200
committerAdriaan Moors <adriaan.moors@epfl.ch>2012-04-26 15:29:07 +0200
commitefd1293df967a10211ca877130f97955be94dc30 (patch)
tree057938c424517a86a1d06cf65fbc9c0b8bc118d3
parent8fc543b5dd7e6a8fa1827cc9e9d65e721cae140e (diff)
downloadscala-efd1293df967a10211ca877130f97955be94dc30.tar.gz
scala-efd1293df967a10211ca877130f97955be94dc30.tar.bz2
scala-efd1293df967a10211ca877130f97955be94dc30.zip
SI-5690: no-selector match in function yields function
the implicit beta-reduction performed by typedFunction on a Function(.., Match(EmptyTree, ...)) must of course only be done when the selector actually is empty... (yes, typedMatchAnonFun needs to be cleaned up, I know)
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala2
-rw-r--r--test/files/pos/virtpatmat_partialfun_nsdnho.scala18
2 files changed, 19 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 934a7567d5..e4c3dcfa55 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -2439,7 +2439,7 @@ trait Typers extends Modes with Adaptations with Taggings with PatMatVirtualiser
fun.body match {
// later phase indicates scaladoc is calling (where shit is messed up, I tell you)
// -- so fall back to old patmat, which is more forgiving
- case Match(sel, cases) if doMatchTranslation =>
+ case Match(sel, cases) if (sel ne EmptyTree) && doMatchTranslation =>
// go to outer context -- must discard the context that was created for the Function since we're discarding the function
// thus, its symbol, which serves as the current context.owner, is not the right owner
// you won't know you're using the wrong owner until lambda lift crashes (unless you know better than to use the wrong owner)
diff --git a/test/files/pos/virtpatmat_partialfun_nsdnho.scala b/test/files/pos/virtpatmat_partialfun_nsdnho.scala
new file mode 100644
index 0000000000..f79e82813c
--- /dev/null
+++ b/test/files/pos/virtpatmat_partialfun_nsdnho.scala
@@ -0,0 +1,18 @@
+class Test {
+ // m.$minus(1)
+ // at scala.Predef$.assert(Predef.scala:185)
+ // at scala.tools.nsc.Global.assert(Global.scala:187)
+ // at scala.tools.nsc.typechecker.SuperAccessors$SuperAccTransformer.transform(SuperAccessors.scala:291)
+ val a: (Map[Int, Int] => (Any => Any)) = { m => { case _ => m - 1} }
+
+ // patmat-crash.scala:9: error: erroneous or inaccessible type
+ val b: (Int => (Any => Any)) = { m => { case _ => m } }
+
+ // no-symbol does not have an owner (this is a bug: scala version 2.10.0-20120420-170445-56c1f29250)
+ // at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:45)
+ // at scala.tools.nsc.Global.abort(Global.scala:202)
+ // at scala.reflect.internal.Symbols$NoSymbol.owner(Symbols.scala:3031)
+ // at scala.tools.nsc.typechecker.SuperAccessors$SuperAccTransformer.hostForAccessorOf(SuperAccessors.scala:474)
+ // at scala.tools.nsc.typechecker.SuperAccessors$SuperAccTransformer.needsProtectedAccessor(SuperAccessors.scala:457)
+ val c: (Int => (Any => Any)) = { m => { case _ => m.toInt } }
+} \ No newline at end of file