aboutsummaryrefslogtreecommitdiff
path: root/compiler/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-01-30 17:51:53 +1100
committerMartin Odersky <odersky@gmail.com>2017-01-31 16:14:18 +1100
commitdd0a8032f70cf7c15a928d5756ce8f27791c9a7d (patch)
treebfd7d0851138b11495e26caa8452b0b799994768 /compiler/src
parent801554c386253ad8474babb2d40590c2c8d3a45c (diff)
downloaddotty-dd0a8032f70cf7c15a928d5756ce8f27791c9a7d.tar.gz
dotty-dd0a8032f70cf7c15a928d5756ce8f27791c9a7d.tar.bz2
dotty-dd0a8032f70cf7c15a928d5756ce8f27791c9a7d.zip
Implement SearchResult.show
Diffstat (limited to 'compiler/src')
-rw-r--r--compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala18
-rw-r--r--compiler/src/dotty/tools/dotc/printing/Printer.scala6
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Implicits.scala12
3 files changed, 31 insertions, 5 deletions
diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
index 61f23c214..ac25f7cfd 100644
--- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
+++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
@@ -6,6 +6,7 @@ import Texts._, Types._, Flags._, Names._, Symbols._, NameOps._, Constants._, De
import Contexts.Context, Scopes.Scope, Denotations.Denotation, Annotations.Annotation
import StdNames.{nme, tpnme}
import ast.Trees._, ast._
+import typer.Implicits._
import config.Config
import java.lang.Integer.toOctalString
import config.Config.summarizeDepth
@@ -484,6 +485,23 @@ class PlainPrinter(_ctx: Context) extends Printer {
}
}.close // todo: override in refined printer
+ def toText(result: SearchResult): Text = result match {
+ case result: SearchSuccess =>
+ "SearchSuccess: " ~ toText(result.ref) ~ " via " ~ toText(result.tree)
+ case result: NonMatchingImplicit =>
+ "NoImplicitMatches"
+ case result: DivergingImplicit =>
+ "Diverging Implicit"
+ case result: ShadowedImplicit =>
+ "Shadowed Implicit"
+ case result: FailedImplicit =>
+ "Failed Implicit"
+ case result: AmbiguousImplicits =>
+ "Ambiguous Implicit: " ~ toText(result.alt1) ~ " and " ~ toText(result.alt2)
+ case _ =>
+ "?Unknown Implicit Result?"
+ }
+
private var maxSummarized = Int.MaxValue
def summarized[T](depth: Int)(op: => T): T = {
diff --git a/compiler/src/dotty/tools/dotc/printing/Printer.scala b/compiler/src/dotty/tools/dotc/printing/Printer.scala
index 14b63012e..506773a4b 100644
--- a/compiler/src/dotty/tools/dotc/printing/Printer.scala
+++ b/compiler/src/dotty/tools/dotc/printing/Printer.scala
@@ -5,6 +5,7 @@ import core._
import Texts._, ast.Trees._
import Types.Type, Symbols.Symbol, Contexts.Context, Scopes.Scope, Constants.Constant,
Names.Name, Denotations._, Annotations.Annotation
+import typer.Implicits.SearchResult
/** The base class of all printers
*/
@@ -94,7 +95,10 @@ abstract class Printer {
/** Textual representation of tree */
def toText[T >: Untyped](tree: Tree[T]): Text
- /** Perform string or text-producing operation `op` so that only a
+ /** Textual representation of implicit search result */
+ def toText(result: SearchResult): Text
+
+ /** Perform string or text-producing operation `op` so that only a
* summarized text with given recursion depth is shown
*/
def summarized[T](depth: Int)(op: => T): T
diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala
index 0b1eb1afb..183dff282 100644
--- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala
@@ -6,7 +6,8 @@ import core._
import ast.{Trees, untpd, tpd, TreeInfo}
import util.Positions._
import util.Stats.{track, record, monitored}
-import printing.Showable
+import printing.{Showable, Printer}
+import printing.Texts._
import Contexts._
import Types._
import Flags._
@@ -219,14 +220,16 @@ object Implicits {
}
/** The result of an implicit search */
- abstract class SearchResult
+ abstract class SearchResult extends Showable {
+ def toText(printer: Printer): Text = printer.toText(this)
+ }
/** A successful search
* @param ref The implicit reference that succeeded
* @param tree The typed tree that needs to be inserted
* @param ctx The context after the implicit search
*/
- case class SearchSuccess(tree: tpd.Tree, ref: TermRef, level: Int, tstate: TyperState) extends SearchResult {
+ case class SearchSuccess(tree: tpd.Tree, ref: TermRef, level: Int, tstate: TyperState) extends SearchResult with Showable {
override def toString = s"SearchSuccess($tree, $ref, $level)"
}
@@ -256,7 +259,7 @@ object Implicits {
}
/** An ambiguous implicits failure */
- class AmbiguousImplicits(alt1: TermRef, alt2: TermRef, val pt: Type, val argument: tpd.Tree) extends ExplainedSearchFailure {
+ class AmbiguousImplicits(val alt1: TermRef, val alt2: TermRef, val pt: Type, val argument: tpd.Tree) extends ExplainedSearchFailure {
def explanation(implicit ctx: Context): String =
em"both ${err.refStr(alt1)} and ${err.refStr(alt2)} $qualify"
override def postscript(implicit ctx: Context) =
@@ -604,6 +607,7 @@ trait Implicits { self: Typer =>
result match {
case result: SearchSuccess =>
result.tstate.commit()
+ implicits.println(i"committing ${result.tstate.constraint} yielding ${ctx.typerState.constraint} ${ctx.typerState.hashesStr}")
result
case result: AmbiguousImplicits =>
val deepPt = pt.deepenProto