Skip to content

Commit

Permalink
Show Implicit Candidate & RefAndLevel
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Aug 8, 2023
1 parent 5759bb8 commit 5b7dc08
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,13 @@ class PlainPrinter(_ctx: Context) extends Printer {
else if (pos.source.exists) s"${pos.source.file.name}:${pos.line + 1}"
else s"(no source file, offset = ${pos.span.point})"

def toText(cand: Candidate): Text =
"Cand("
~ toTextRef(cand.ref)
~ (if cand.isConversion then " conv" else "")
~ (if cand.isExtension then " ext" else "")
~ Str(" L" + cand.level) ~ ")"

def toText(result: SearchResult): Text = result match {
case result: SearchSuccess =>
"SearchSuccess: " ~ toText(result.ref) ~ " via " ~ toText(result.tree)
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/printing/Printer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Texts._, ast.Trees._
import Types.{Type, SingletonType, LambdaParam, NamedType},
Symbols.Symbol, Scopes.Scope, Constants.Constant,
Names.Name, Denotations._, Annotations.Annotation, Contexts.Context
import typer.Implicits.SearchResult
import typer.Implicits.*
import util.SourcePosition
import typer.ImportInfo

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

/** Textual representation of implicit candidates. */
def toText(cand: Candidate): Text

/** Textual representation of implicit search result */
def toText(result: SearchResult): Text

Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,19 @@ object Implicits:
}

/** Both search candidates and successes are references with a specific nesting level. */
sealed trait RefAndLevel {
sealed trait RefAndLevel extends Showable {
def ref: TermRef
def level: Int
}

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

def isExtension = (kind & Candidate.Extension) != 0
def isConversion = (kind & Candidate.Conversion) != 0

def toText(printer: Printer): Text = printer.toText(this)
}
object Candidate {
type Kind = Int
Expand Down

0 comments on commit 5b7dc08

Please sign in to comment.