diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 3 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Unapplies.scala | 2 | ||||
-rw-r--r-- | test/files/neg/t7877.check | 7 | ||||
-rw-r--r-- | test/files/neg/t7877.scala | 13 |
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 157c6ba4de..37a6d50efc 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 af19e3cf80..2411a23e7d 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 +} |