@@ -5,6 +5,7 @@ package typer
5
5
import ast .{tpd , untpd }
6
6
import ast .Trees ._
7
7
import core ._
8
+ import printing .{Printer , Showable }
8
9
import util .SimpleMap
9
10
import Symbols ._ , Names ._ , Denotations ._ , Types ._ , Contexts ._ , StdNames ._ , Flags ._
10
11
import Decorators .StringInterpolators
@@ -28,7 +29,7 @@ object ImportInfo {
28
29
* scala.Predef or dotty.DottyPredef in the start context, false otherwise.
29
30
*/
30
31
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 {
32
33
33
34
// Dotty deviation: we cannot use a lazy val here for the same reason
34
35
// that we cannot use one for `DottyPredefModuleRef`.
@@ -91,7 +92,7 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree],
91
92
}
92
93
93
94
/** The implicit references imported by this import clause */
94
- def importedImplicits : List [TermRef ] = {
95
+ def importedImplicits ( implicit ctx : Context ) : List [TermRef ] = {
95
96
val pre = site
96
97
if (isWildcardImport) {
97
98
val refs = pre.implicitMembers
@@ -115,23 +116,21 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree],
115
116
* override import Predef.{any2stringAdd => _, StringAdd => _, _} // disables String +
116
117
* override import java.lang.{} // disables all imports
117
118
*/
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 )
123
130
}
124
- if (maybeShadowsRoot && defn.RootImportTypes .exists(_.symbol == sym)) sym
125
- else NoSymbol
131
+ myUnimported
126
132
}
133
+ private [this ] var myUnimported : Symbol = _
127
134
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 )
137
136
}
0 commit comments