Skip to content

Commit 6e2c6e0

Browse files
committed
Better printing of import symbols
Had duplications of `import` before. Also: add import info when printing contexts.
1 parent 28c2e04 commit 6e2c6e0

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,11 @@ object Contexts {
422422
final def withOwner(owner: Symbol): Context =
423423
if (owner ne this.owner) fresh.setOwner(owner) else this
424424

425-
override def toString =
425+
override def toString = {
426+
def iinfo(implicit ctx: Context) = if (ctx.importInfo == null) "" else i"${ctx.importInfo.selectors}%, %"
426427
"Context(\n" +
427-
(outersIterator map ( ctx => s" owner = ${ctx.owner}, scope = ${ctx.scope}") mkString "\n")
428+
(outersIterator map ( ctx => s" owner = ${ctx.owner}, scope = ${ctx.scope}, import = ${iinfo(ctx)}") mkString "\n")
429+
}
428430
}
429431

430432
/** A condensed context provides only a small memory footprint over

src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
351351
case SeqLiteral(elems, elemtpt) =>
352352
"[" ~ toTextGlobal(elems, ",") ~ " : " ~ toText(elemtpt) ~ "]"
353353
case tree @ Inlined(call, bindings, body) =>
354-
(("/* inlined from " ~ toText(call) ~ "*/ ") provided !homogenizedView) ~
354+
(("/* inlined from " ~ toText(call) ~ "*/ ") provided !homogenizedView) ~
355355
blockText(bindings :+ body)
356356
case tpt: untpd.DerivedTypeTree =>
357357
"<derived typetree watching " ~ summarized(toText(tpt.watched)) ~ ">"
@@ -525,11 +525,11 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
525525
if (tree.isType) txt = toText(tp)
526526
else if (!tree.isDef) txt = ("<" ~ txt ~ ":" ~ toText(tp) ~ ">").close
527527
}
528-
else if (homogenizedView && tree.isType)
528+
else if (homogenizedView && tree.isType)
529529
txt = toText(tree.typeOpt)
530530
if (ctx.settings.Yprintpos.value && !tree.isInstanceOf[WithoutTypeOrPos[_]]) {
531-
val pos =
532-
if (homogenizedView && !tree.isInstanceOf[MemberDef]) tree.pos.toSynthetic
531+
val pos =
532+
if (homogenizedView && !tree.isInstanceOf[MemberDef]) tree.pos.toSynthetic
533533
else tree.pos
534534
val clsStr = "" // DEBUG: if (tree.isType) tree.getClass.toString else ""
535535
txt = (txt ~ "@" ~ pos.toString ~ clsStr).close
@@ -559,14 +559,12 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
559559
(sym.allOverriddenSymbols exists (_ is TypeParam))
560560

561561
override def toText(sym: Symbol): Text = {
562-
if (sym.isImport) {
563-
def importString(tree: untpd.Tree) = s"import ${tree.show}"
562+
if (sym.isImport)
564563
sym.infoOrCompleter match {
565-
case info: Namer#Completer => return importString(info.original)
566-
case info: ImportType => return importString(info.expr)
564+
case info: Namer#Completer => return info.original.show
565+
case info: ImportType => return s"import $info.expr.show"
567566
case _ =>
568567
}
569-
}
570568
if (sym.is(ModuleClass))
571569
kindString(sym) ~~ (nameString(sym.name.stripModuleClassSuffix) + idString(sym))
572570
else

0 commit comments

Comments
 (0)