aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/reporting
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-09-15 18:04:03 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-10-10 13:25:32 +0200
commitc9a8bb8d783d288ae2c165b8eefb3ca47c372c4e (patch)
tree15944309b9fdbbf27df32872cc4e98d9de7b3621 /src/dotty/tools/dotc/reporting
parent66f7f7d23264374f9fbc581538fa1f47de16433c (diff)
downloaddotty-c9a8bb8d783d288ae2c165b8eefb3ca47c372c4e.tar.gz
dotty-c9a8bb8d783d288ae2c165b8eefb3ca47c372c4e.tar.bz2
dotty-c9a8bb8d783d288ae2c165b8eefb3ca47c372c4e.zip
Add more examples to Typer
Diffstat (limited to 'src/dotty/tools/dotc/reporting')
-rw-r--r--src/dotty/tools/dotc/reporting/Examples.scala32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/reporting/Examples.scala b/src/dotty/tools/dotc/reporting/Examples.scala
index 9759d39e8..652620e29 100644
--- a/src/dotty/tools/dotc/reporting/Examples.scala
+++ b/src/dotty/tools/dotc/reporting/Examples.scala
@@ -2,8 +2,10 @@ package dotty.tools
package dotc
package reporting
-import dotc.core.Contexts.Context
+import dotc.core._
+import Contexts.Context, Decorators._, Symbols._
import dotc.printing.SyntaxHighlighting._
+import util.{SourcePosition, NoSourcePosition}
object ErrorExplanations {
import dotc.ast.Trees._
@@ -73,4 +75,32 @@ object ErrorExplanations {
val msg =
hl"""A ${"try"} without ${"catch"} or ${"finally"} is equivalent to putting its body in a block; no exceptions are handled."""
}
+
+ case class DuplicateBind(bind: untpd.Bind, tree: untpd.CaseDef)(implicit ctx: Context) extends Explanation {
+ val msg =
+ em"duplicate pattern variable: `${bind.name}`"
+
+ val explanation = {
+ val pat = tree.pat.show
+ val guard = tree.guard match {
+ case untpd.EmptyTree => ""
+ case guard => s"if ${guard.show}"
+ }
+
+ val body = tree.body match {
+ case Block(Nil, untpd.EmptyTree) => ""
+ case body => s" ${body.show}"
+ }
+
+ val caseDef = s"case $pat$guard => $body"
+
+ hl"""|Explanation
+ |===========
+ |For each ${"case"} bound variable names have to be unique. In:
+ |
+ |$caseDef
+ |
+ |`${bind.name}` is not unique. Rename one of the binds!""".stripMargin
+ }
+ }
}