Skip to content

Commit 5b330f1

Browse files
committed
ImportInfo: removed ctx parameter from constructor
ImportInfo#toString required the ctx parameter,so it was replaced by ImportInfo#toText.
1 parent 42e112b commit 5b330f1

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Contexts.Context, Scopes.Scope, Denotations.Denotation, Annotations.Annot
77
import StdNames.{nme, tpnme}
88
import ast.Trees._, ast._
99
import typer.Implicits._
10+
import typer.ImportInfo
1011
import config.Config
1112
import java.lang.Integer.toOctalString
1213
import config.Config.summarizeDepth
@@ -502,6 +503,17 @@ class PlainPrinter(_ctx: Context) extends Printer {
502503
"?Unknown Implicit Result?"
503504
}
504505

506+
def toText(importInfo: ImportInfo): Text = {
507+
val siteStr = importInfo.site.show
508+
val exprStr = if (siteStr endsWith ".type") siteStr dropRight 5 else siteStr
509+
val selectorStr = importInfo.selectors match {
510+
case Ident(name) :: Nil => name.show
511+
case _ => "{...}"
512+
}
513+
s"import $exprStr.$selectorStr"
514+
}
515+
516+
505517
private var maxSummarized = Int.MaxValue
506518

507519
def summarized[T](depth: Int)(op: => T): T = {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Texts._, ast.Trees._
66
import Types.Type, Symbols.Symbol, Contexts.Context, Scopes.Scope, Constants.Constant,
77
Names.Name, Denotations._, Annotations.Annotation
88
import typer.Implicits.SearchResult
9+
import typer.ImportInfo
910

1011
/** The base class of all printers
1112
*/
@@ -98,6 +99,9 @@ abstract class Printer {
9899
/** Textual representation of implicit search result */
99100
def toText(result: SearchResult): Text
100101

102+
/** Textual representation of info relating to an import clause */
103+
def toText(result: ImportInfo): Text
104+
101105
/** Perform string or text-producing operation `op` so that only a
102106
* summarized text with given recursion depth is shown
103107
*/

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package typer
55
import ast.{tpd, untpd}
66
import ast.Trees._
77
import core._
8+
import printing.{Printer, Showable}
89
import util.SimpleMap
910
import Symbols._, Names._, Denotations._, Types._, Contexts._, StdNames._, Flags._
1011
import Decorators.StringInterpolators
@@ -28,7 +29,7 @@ object ImportInfo {
2829
* scala.Predef or dotty.DottyPredef in the start context, false otherwise.
2930
*/
3031
class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree],
31-
symNameOpt: Option[TermName], val isRootImport: Boolean = false)(implicit ctx: Context) {
32+
symNameOpt: Option[TermName], val isRootImport: Boolean = false) extends Showable {
3233

3334
// Dotty deviation: we cannot use a lazy val here for the same reason
3435
// that we cannot use one for `DottyPredefModuleRef`.
@@ -91,7 +92,7 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree],
9192
}
9293

9394
/** The implicit references imported by this import clause */
94-
def importedImplicits: List[TermRef] = {
95+
def importedImplicits(implicit ctx: Context): List[TermRef] = {
9596
val pre = site
9697
if (isWildcardImport) {
9798
val refs = pre.implicitMembers
@@ -115,23 +116,21 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree],
115116
* override import Predef.{any2stringAdd => _, StringAdd => _, _} // disables String +
116117
* override import java.lang.{} // disables all imports
117118
*/
118-
lazy val unimported: Symbol = {
119-
lazy val sym = site.termSymbol
120-
def maybeShadowsRoot = symNameOpt match {
121-
case Some(symName) => defn.ShadowableImportNames.contains(symName)
122-
case None => false
119+
def unimported(implicit ctx: Context): Symbol = {
120+
if (myUnimported == null) {
121+
lazy val sym = site.termSymbol
122+
def maybeShadowsRoot = symNameOpt match {
123+
case Some(symName) => defn.ShadowableImportNames.contains(symName)
124+
case None => false
125+
}
126+
myUnimported =
127+
if (maybeShadowsRoot && defn.RootImportTypes.exists(_.symbol == sym)) sym
128+
else NoSymbol
129+
assert(myUnimported != null)
123130
}
124-
if (maybeShadowsRoot && defn.RootImportTypes.exists(_.symbol == sym)) sym
125-
else NoSymbol
131+
myUnimported
126132
}
133+
private[this] var myUnimported: Symbol = _
127134

128-
override def toString = {
129-
val siteStr = site.show
130-
val exprStr = if (siteStr endsWith ".type") siteStr dropRight 5 else siteStr
131-
val selectorStr = selectors match {
132-
case Ident(name) :: Nil => name.show
133-
case _ => "{...}"
134-
}
135-
i"import $exprStr.$selectorStr"
136-
}
135+
def toText(printer: Printer) = printer.toText(this)
137136
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
145145
*/
146146
def bindingString(prec: Int, whereFound: Context, qualifier: String = "") =
147147
if (prec == wildImport || prec == namedImport) {
148-
ex"""imported$qualifier by ${hl"${whereFound.importInfo.toString}"}"""
148+
ex"""imported$qualifier by ${hl"${whereFound.importInfo}"}"""
149149
} else
150150
ex"""defined$qualifier in ${hl"${whereFound.owner.toString}"}"""
151151

0 commit comments

Comments
 (0)