summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2016-01-29 15:09:45 +1000
committerJason Zaugg <jzaugg@gmail.com>2016-01-29 15:09:45 +1000
commitddd83de2bc44471353e34d20fae037cc88267838 (patch)
tree1f774ad5d590aed133e3cac15efb917a1568c7c3
parent6f9c65d784ddc0df3accf8ca821c7f9e081110f0 (diff)
parentb2093f2345b991fa4774950c5505621ab6445897 (diff)
downloadscala-ddd83de2bc44471353e34d20fae037cc88267838.tar.gz
scala-ddd83de2bc44471353e34d20fae037cc88267838.tar.bz2
scala-ddd83de2bc44471353e34d20fae037cc88267838.zip
Merge pull request #4917 from retronym/ticket/9629
SI-9629 Emit missing 'pattern must be a value' error
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala8
-rw-r--r--test/files/neg/t9629.check17
-rw-r--r--test/files/neg/t9629.scala12
3 files changed, 33 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index bf64ed9baa..3a8edafd58 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -5421,6 +5421,9 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
if (!isPastTyper)
signalDone(context.asInstanceOf[analyzer.Context], tree, result)
+ if (mode.inPatternMode && !mode.inPolyMode && result.isType)
+ PatternMustBeValue(result, pt)
+
result
}
@@ -5510,10 +5513,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
// as a compromise, context.enrichmentEnabled tells adaptToMember to go ahead and enrich,
// but arbitrary conversions (in adapt) are disabled
// TODO: can we achieve the pattern matching bit of the string interpolation SIP without this?
- typingInPattern(context.withImplicitsDisabledAllowEnrichment(typed(tree, PATTERNmode, pt))) match {
- case tpt if tpt.isType => PatternMustBeValue(tpt, pt); tpt
- case pat => pat
- }
+ typingInPattern(context.withImplicitsDisabledAllowEnrichment(typed(tree, PATTERNmode, pt)))
}
/** Types a (fully parameterized) type tree */
diff --git a/test/files/neg/t9629.check b/test/files/neg/t9629.check
new file mode 100644
index 0000000000..4eafa84236
--- /dev/null
+++ b/test/files/neg/t9629.check
@@ -0,0 +1,17 @@
+t9629.scala:4: error: pattern must be a value: Option[Int]
+Note: if you intended to match against the class, try `case _: Option[_]`
+ case Option[Int] => // error was issued before
+ ^
+t9629.scala:5: error: pattern must be a value: Option[Int]
+Note: if you intended to match against the class, try `case _: Option[_]`
+ case Some(Option[Int]) => // error was skipped, patmat issued an internal error
+ ^
+t9629.scala:8: error: pattern must be a value: Option[Int]
+Note: if you intended to match against the class, try `case _: Option[_]`
+ case (_, Option[Int]) =>
+ ^
+t9629.scala:9: error: pattern must be a value: Option[Int]
+Note: if you intended to match against the class, try `case _: Option[_]`
+ case x @ (y @ Option[Int]) =>
+ ^
+four errors found
diff --git a/test/files/neg/t9629.scala b/test/files/neg/t9629.scala
new file mode 100644
index 0000000000..2be2b039f2
--- /dev/null
+++ b/test/files/neg/t9629.scala
@@ -0,0 +1,12 @@
+class Test {
+ def foo(a: Any) {
+ a match {
+ case Option[Int] => // error was issued before
+ case Some(Option[Int]) => // error was skipped, patmat issued an internal error
+
+ // variations
+ case (_, Option[Int]) =>
+ case x @ (y @ Option[Int]) =>
+ }
+ }
+}