summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-09-27 13:19:39 -0700
committerJason Zaugg <jzaugg@gmail.com>2013-09-27 13:19:39 -0700
commit091f3ba3a8a427d69f7cc7d2fafeebb38126ec93 (patch)
tree995a4fa0ace0853ddcde645b645a73eb2d5bfb43
parent4b89ce639912d2143cc06ddb3b7da77c8fa8521d (diff)
parentd290d0d1afe122fdeb3798364be7cda72cc182ec (diff)
downloadscala-091f3ba3a8a427d69f7cc7d2fafeebb38126ec93.tar.gz
scala-091f3ba3a8a427d69f7cc7d2fafeebb38126ec93.tar.bz2
scala-091f3ba3a8a427d69f7cc7d2fafeebb38126ec93.zip
Merge pull request #2992 from retronym/ticket/7877
Only look for unapplies in term trees
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala3
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Unapplies.scala2
-rw-r--r--test/files/neg/t7877.check7
-rw-r--r--test/files/neg/t7877.scala13
4 files changed, 23 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 311c0e09e3..e0ea555fe8 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -3245,7 +3245,8 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
if (!tree.isErrorTyped) setError(tree) else tree
// @H change to setError(treeCopy.Apply(tree, fun, args))
- case ExtractorType(unapply) if mode.inPatternMode =>
+ // SI-7877 `isTerm` needed to exclude `class T[A] { def unapply(..) }; ... case T[X] =>`
+ case HasUnapply(unapply) if mode.inPatternMode && fun.isTerm =>
if (unapply == QuasiquoteClass_api_unapply) macroExpandUnapply(this, tree, fun, unapply, args, mode, pt)
else doTypedUnapply(tree, fun0, fun, args, mode, pt)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
index 0c7c42db17..ed96f66ab8 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
@@ -39,7 +39,7 @@ trait Unapplies extends ast.TreeDSL {
*/
def unapplyMember(tp: Type): Symbol = directUnapplyMember(tp) filter (sym => !hasMultipleNonImplicitParamLists(sym))
- object ExtractorType {
+ object HasUnapply {
def unapply(tp: Type): Option[Symbol] = unapplyMember(tp).toOption
}
diff --git a/test/files/neg/t7877.check b/test/files/neg/t7877.check
new file mode 100644
index 0000000000..7f7f832463
--- /dev/null
+++ b/test/files/neg/t7877.check
@@ -0,0 +1,7 @@
+t7877.scala:6: error: not found: value Y
+ case Y() => () // not allowed
+ ^
+t7877.scala:7: error: OnNext[Any] does not take parameters
+ case OnNext[Any]() => () // should *not* be allowed, but was.
+ ^
+two errors found
diff --git a/test/files/neg/t7877.scala b/test/files/neg/t7877.scala
new file mode 100644
index 0000000000..52e167f3b8
--- /dev/null
+++ b/test/files/neg/t7877.scala
@@ -0,0 +1,13 @@
+class Test {
+ val X: OnNext[Any] = null
+ def Y: OnNext[Any] = null
+ (null: Any) match {
+ case X() => () // allowed
+ case Y() => () // not allowed
+ case OnNext[Any]() => () // should *not* be allowed, but was.
+ }
+}
+
+class OnNext[+T] {
+ def unapply(x: Any) = false
+}