aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Applications.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-04-27 13:59:17 +0200
committerMartin Odersky <odersky@gmail.com>2016-04-27 14:01:42 +0200
commit42b20d7143eb3da8dbe536ef990ceef4ec861b25 (patch)
tree1946bab1daf2f58cc4ff4a2f69f100e593d0713b /src/dotty/tools/dotc/typer/Applications.scala
parent6c0184b157dd218d4b6f854e7142efdf074e596c (diff)
downloaddotty-42b20d7143eb3da8dbe536ef990ceef4ec861b25.tar.gz
dotty-42b20d7143eb3da8dbe536ef990ceef4ec861b25.tar.bz2
dotty-42b20d7143eb3da8dbe536ef990ceef4ec861b25.zip
Better error diagnostics for "not an extractor" errors.
Now explains in detail why an possibly found unapply or unapplySeq is ineligible.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Applications.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index 37a9f0ba0..13616ea6c 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -659,8 +659,23 @@ 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(tree: Tree) =
- errorTree(tree, s"${qual.show} cannot be used as an extractor in a pattern because it lacks an unapply or unapplySeq method")
+ 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")
+ }
/** 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