Skip to content

Commit 5b7dc08

Browse files
committed
Show Implicit Candidate & RefAndLevel
1 parent 5759bb8 commit 5b7dc08

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

+7
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,13 @@ class PlainPrinter(_ctx: Context) extends Printer {
641641
else if (pos.source.exists) s"${pos.source.file.name}:${pos.line + 1}"
642642
else s"(no source file, offset = ${pos.span.point})"
643643

644+
def toText(cand: Candidate): Text =
645+
"Cand("
646+
~ toTextRef(cand.ref)
647+
~ (if cand.isConversion then " conv" else "")
648+
~ (if cand.isExtension then " ext" else "")
649+
~ Str(" L" + cand.level) ~ ")"
650+
644651
def toText(result: SearchResult): Text = result match {
645652
case result: SearchSuccess =>
646653
"SearchSuccess: " ~ toText(result.ref) ~ " via " ~ toText(result.tree)

compiler/src/dotty/tools/dotc/printing/Printer.scala

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Texts._, ast.Trees._
77
import Types.{Type, SingletonType, LambdaParam, NamedType},
88
Symbols.Symbol, Scopes.Scope, Constants.Constant,
99
Names.Name, Denotations._, Annotations.Annotation, Contexts.Context
10-
import typer.Implicits.SearchResult
10+
import typer.Implicits.*
1111
import util.SourcePosition
1212
import typer.ImportInfo
1313

@@ -153,6 +153,9 @@ abstract class Printer {
153153
/** Textual representation of source position */
154154
def toText(pos: SourcePosition): Text
155155

156+
/** Textual representation of implicit candidates. */
157+
def toText(cand: Candidate): Text
158+
156159
/** Textual representation of implicit search result */
157160
def toText(result: SearchResult): Text
158161

compiler/src/dotty/tools/dotc/typer/Implicits.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,19 @@ object Implicits:
4949
}
5050

5151
/** Both search candidates and successes are references with a specific nesting level. */
52-
sealed trait RefAndLevel {
52+
sealed trait RefAndLevel extends Showable {
5353
def ref: TermRef
5454
def level: Int
5555
}
5656

5757
/** An eligible implicit candidate, consisting of an implicit reference and a nesting level */
58-
case class Candidate(implicitRef: ImplicitRef, kind: Candidate.Kind, level: Int) extends RefAndLevel {
58+
case class Candidate(implicitRef: ImplicitRef, kind: Candidate.Kind, level: Int) extends RefAndLevel with Showable {
5959
def ref: TermRef = implicitRef.underlyingRef
6060

6161
def isExtension = (kind & Candidate.Extension) != 0
6262
def isConversion = (kind & Candidate.Conversion) != 0
63+
64+
def toText(printer: Printer): Text = printer.toText(this)
6365
}
6466
object Candidate {
6567
type Kind = Int

0 commit comments

Comments
 (0)