aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala19
-rw-r--r--tests/neg/extractors.scala27
2 files changed, 2 insertions, 44 deletions
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index 13616ea6c..37a9f0ba0 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -659,23 +659,8 @@ trait Applications extends Compatibility { self: Typer =>
def typedUnApply(tree: untpd.Apply, selType: Type)(implicit ctx: Context): Tree = track("typedUnApply") {
val Apply(qual, args) = tree
- def notAnExtractor(unapplyFn: Tree) = {
- val methodStr = unapplyFn.symbol.name match {
- case nme.unapply => "unapply"
- case nme.unapplySeq => "unapplySeq"
- case _ => "unapply or unapplySeq"
- }
- val because = unapplyFn.tpe.widen match {
- case mt: MethodType =>
- i"its $methodStr method of type $mt" + (
- if (mt.isDependent) i" has a dependent type"
- else if (mt.paramTypes.length != 1) i" does not take a single parameter"
- else " is not eligible (this could be an internal compiler error)")
- case _ =>
- "it lacks a unapply or unapplySeq method"
- }
- errorTree(unapplyFn, s"${qual.show} cannot be used as an extractor in a pattern $because")
- }
+ def notAnExtractor(tree: Tree) =
+ errorTree(tree, s"${qual.show} cannot be used as an extractor in a pattern because it lacks an unapply or unapplySeq method")
/** If this is a term ref tree, try to typecheck with its type name.
* If this refers to a type alias, follow the alias, and if
diff --git a/tests/neg/extractors.scala b/tests/neg/extractors.scala
deleted file mode 100644
index 88600da76..000000000
--- a/tests/neg/extractors.scala
+++ /dev/null
@@ -1,27 +0,0 @@
-object A {}
-
-object B {
-
- def unapply[T](x: T): Option[x.type] = ???
-
-}
-
-object C {
- def unapply[T](x: T, y: T): Option[T] = ???
-}
-
-object D {
- def unapply[T](): Option[T] = ???
-}
-
-object Test {
-
- val x: Any = ???
- x match {
- case A(y) => ??? // error: A cannot be used as an extractor in a pattern it lacks a unapply or unapplySeq method
- case B(y) => ??? // error: B cannot be used as an extractor in a pattern its unapply method of type (x: T)Option[T(x)] has a dependent type
- case C(y) => ??? // error: C cannot be used as an extractor in a pattern its unapply method of type (x: T, y: T)Option[T] does not take a single parameter
- case D(y) => ??? // error: D cannot be used as an extractor in a pattern its unapply method of type ()Option[T] does not take a single parameter
- }
-
-}