aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer
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/typer
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/typer')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 3e3bb32f5..19297f9ec 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -37,6 +37,8 @@ import rewrite.Rewrites.patch
import NavigateAST._
import transform.SymUtils._
import language.implicitConversions
+import printing.SyntaxHighlighting._
+import reporting.ErrorExplanations._
object Typer {
@@ -141,9 +143,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
* imported by <tree>
* or defined in <symbol>
*/
- def bindingString(prec: Int, whereFound: Context, qualifier: String = "")(implicit ctx: Context) =
- if (prec == wildImport || prec == namedImport) ex"imported$qualifier by ${whereFound.importInfo}"
- else ex"defined$qualifier in ${whereFound.owner}"
+ def bindingString(prec: Int, whereFound: Context, qualifier: String = "") =
+ if (prec == wildImport || prec == namedImport) {
+ ex"""imported$qualifier by ${hl"${whereFound.importInfo.toString}"}"""
+ } else
+ ex"""defined$qualifier in ${hl"${whereFound.owner.toString}"}"""
/** Check that any previously found result from an inner context
* does properly shadow the new one from an outer context.
@@ -166,9 +170,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
else {
if (!scala2pkg && !previous.isError && !found.isError) {
error(
- ex"""reference to $name is ambiguous;
- |it is both ${bindingString(newPrec, ctx, "")}
- |and ${bindingString(prevPrec, prevCtx, " subsequently")}""",
+ ex"""|reference to `$name` is ambiguous
+ |it is both ${bindingString(newPrec, ctx, "")}
+ |and ${bindingString(prevPrec, prevCtx, " subsequently")}""",
tree.pos)
}
previous
@@ -181,7 +185,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
def checkUnambiguous(found: Type) = {
val other = namedImportRef(site, selectors.tail)
if (other.exists && found.exists && (found != other))
- error(em"reference to $name is ambiguous; it is imported twice in ${ctx.tree}",
+ error(em"reference to `$name` is ambiguous; it is imported twice in ${ctx.tree}",
tree.pos)
found
}
@@ -839,11 +843,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
mapOver(t)
}
}
- override def transform(tree: Tree)(implicit ctx: Context) =
- super.transform(tree.withType(elimWildcardSym(tree.tpe))) match {
+ override def transform(trt: Tree)(implicit ctx: Context) =
+ super.transform(trt.withType(elimWildcardSym(trt.tpe))) match {
case b: Bind =>
if (ctx.scope.lookup(b.name) == NoSymbol) ctx.enter(b.symbol)
- else ctx.error(em"duplicate pattern variable: ${b.name}", b.pos)
+ else ctx.explainError(DuplicateBind(b, tree), b.pos)
b.symbol.info = elimWildcardSym(b.symbol.info)
b
case t => t