summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-09-05 17:04:34 +0200
committerJason Zaugg <jzaugg@gmail.com>2013-09-06 17:29:21 +0200
commit3e1631e8f71f73f5275b1595bd85de25625bb2de (patch)
treee6542f461fc4515a231522bccb7117d5feccc255
parenta8c05274f738943ae58ecefda4b012b9daf5d8dc (diff)
downloadscala-3e1631e8f71f73f5275b1595bd85de25625bb2de.tar.gz
scala-3e1631e8f71f73f5275b1595bd85de25625bb2de.tar.bz2
scala-3e1631e8f71f73f5275b1595bd85de25625bb2de.zip
SI-7643 Enable newPatternMatching in interactive.
Without it, the enclosed test fails with: ArrayBuffer(Problem(RangePosition(partial-fun/src/PartialFun.scala, 62, 62, 77),type mismatch; found : Int => Int required: PartialFunction[Int,Int],2)) And with that, we can remove this option altogether.
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala6
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala6
-rw-r--r--src/interactive/scala/tools/nsc/interactive/Global.scala1
-rw-r--r--test/files/presentation/partial-fun.check2
-rw-r--r--test/files/presentation/partial-fun/Runner.scala10
-rw-r--r--test/files/presentation/partial-fun/partial-fun.check1
-rw-r--r--test/files/presentation/partial-fun/src/PartialFun.scala5
7 files changed, 21 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala b/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala
index 8bf9ce49be..38a3f18bf8 100644
--- a/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala
@@ -45,12 +45,6 @@ trait PatternTypers {
}
}
- // when true:
- // - we may virtualize matches (if -Xexperimental and there's a suitable __match in scope)
- // - we synthesize PartialFunction implementations for `x => x match {...}` and `match {...}` when the expected type is PartialFunction
- // this is disabled by: interactive compilation (we run it for scaladoc due to SI-5933)
- protected def newPatternMatching = true // presently overridden in the presentation compiler
-
trait PatternTyper {
self: Typer =>
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index dd16b5be85..e9c506374d 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -2436,7 +2436,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
// TODO: add fallback __match sentinel to predef
val matchStrategy: Tree =
- if (!(newPatternMatching && settings.Xexperimental && context.isNameInScope(vpmName._match))) null // fast path, avoiding the next line if there's no __match to be seen
+ if (!(settings.Xexperimental && context.isNameInScope(vpmName._match))) null // fast path, avoiding the next line if there's no __match to be seen
else newTyper(context.makeImplicit(reportAmbiguousErrors = false)).silent(_.typed(Ident(vpmName._match)), reportAmbiguousErrors = false) orElse (_ => null)
if (matchStrategy ne null) // virtualize
@@ -2713,7 +2713,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
fun.body match {
// translate `x => x match { <cases> }` : PartialFunction to
// `new PartialFunction { def applyOrElse(x, default) = x match { <cases> } def isDefinedAt(x) = ... }`
- case Match(sel, cases) if (sel ne EmptyTree) && newPatternMatching && (pt.typeSymbol == PartialFunctionClass) =>
+ case Match(sel, cases) if (sel ne EmptyTree) && (pt.typeSymbol == PartialFunctionClass) =>
// 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)
@@ -3997,7 +3997,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
val selector = tree.selector
val cases = tree.cases
if (selector == EmptyTree) {
- if (newPatternMatching && (pt.typeSymbol == PartialFunctionClass))
+ if (pt.typeSymbol == PartialFunctionClass)
synthesizePartialFunction(newTermName(context.unit.fresh.newName("x")), tree.pos, tree, mode, pt)
else {
val arity = if (isFunctionType(pt)) pt.dealiasWiden.typeArgs.length - 1 else 1
diff --git a/src/interactive/scala/tools/nsc/interactive/Global.scala b/src/interactive/scala/tools/nsc/interactive/Global.scala
index 721fbf24c7..bc6df9eb25 100644
--- a/src/interactive/scala/tools/nsc/interactive/Global.scala
+++ b/src/interactive/scala/tools/nsc/interactive/Global.scala
@@ -32,7 +32,6 @@ trait InteractiveAnalyzer extends Analyzer {
override def newTyper(context: Context): InteractiveTyper = new Typer(context) with InteractiveTyper
override def newNamer(context: Context): InteractiveNamer = new Namer(context) with InteractiveNamer
- override protected def newPatternMatching = false
trait InteractiveTyper extends Typer {
override def canAdaptConstantTypeToLiteral = false
diff --git a/test/files/presentation/partial-fun.check b/test/files/presentation/partial-fun.check
new file mode 100644
index 0000000000..0352d5e5c8
--- /dev/null
+++ b/test/files/presentation/partial-fun.check
@@ -0,0 +1,2 @@
+reload: PartialFun.scala
+ArrayBuffer()
diff --git a/test/files/presentation/partial-fun/Runner.scala b/test/files/presentation/partial-fun/Runner.scala
new file mode 100644
index 0000000000..3edd5bb5b0
--- /dev/null
+++ b/test/files/presentation/partial-fun/Runner.scala
@@ -0,0 +1,10 @@
+import scala.tools.nsc.interactive.tests.InteractiveTest
+
+object Test extends InteractiveTest {
+ override def runDefaultTests() {
+ sourceFiles foreach (src => askLoadedTyped(src).get)
+ super.runDefaultTests()
+
+ println(compiler.unitOfFile.values.map(_.problems).mkString("", "\n", ""))
+ }
+}
diff --git a/test/files/presentation/partial-fun/partial-fun.check b/test/files/presentation/partial-fun/partial-fun.check
new file mode 100644
index 0000000000..adceab8280
--- /dev/null
+++ b/test/files/presentation/partial-fun/partial-fun.check
@@ -0,0 +1 @@
+reload: PartialFun.scala
diff --git a/test/files/presentation/partial-fun/src/PartialFun.scala b/test/files/presentation/partial-fun/src/PartialFun.scala
new file mode 100644
index 0000000000..4657898ed1
--- /dev/null
+++ b/test/files/presentation/partial-fun/src/PartialFun.scala
@@ -0,0 +1,5 @@
+class A {
+ def foo {
+ val x: PartialFunction[Int, Int] = ({ case 0 => 0 })
+ }
+}