Skip to content

Commit a52ca60

Browse files
committed
Merge pull request #539 from dotty-staging/fix/bootstrap-predef
Allow to compile root import classes without special option.
2 parents 7129cbe + 2fdf660 commit a52ca60

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,9 @@ class Compiler {
104104
.setMode(Mode.ImplicitsEnabled)
105105
.setTyperState(new MutableTyperState(ctx.typerState, new ConsoleReporter()(ctx), isCommittable = true))
106106
ctx.definitions.init(start) // set context of definitions to start
107-
start.setRunInfo(new RunInfo(start))
108-
def addImport(ctx: Context, sym: Symbol) =
109-
ctx.fresh.setImportInfo(ImportInfo.rootImport(sym)(ctx))
110-
if (ctx.settings.YnoImports.value) start
111-
else (start /: defn.RootImports)(addImport)
107+
def addImport(ctx: Context, symf: () => Symbol) =
108+
ctx.fresh.setImportInfo(ImportInfo.rootImport(symf)(ctx))
109+
(start.setRunInfo(new RunInfo(start)) /: defn.RootImportFns)(addImport)
112110
}
113111

114112
def reset()(implicit ctx: Context): Unit = {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,9 @@ class Definitions {
449449

450450
lazy val isPolymorphicAfterErasure = Set[Symbol](Any_isInstanceOf, Any_asInstanceOf, newRefArrayMethod)
451451

452-
lazy val RootImports = List[Symbol](JavaLangPackageVal, ScalaPackageVal, ScalaPredefModule, DottyPredefModule)
452+
val RootImportFns = List[() => Symbol](() => JavaLangPackageVal, () => ScalaPackageVal, () => ScalaPredefModule, () => DottyPredefModule)
453+
454+
lazy val RootImports = RootImportFns.map(_())
453455

454456
def isTupleType(tp: Type)(implicit ctx: Context) = {
455457
val arity = tp.dealias.argInfos.length

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import Decorators.StringInterpolators
1111

1212
object ImportInfo {
1313
/** The import info for a root import from given symbol `sym` */
14-
def rootImport(sym: Symbol)(implicit ctx: Context) = {
15-
val expr = tpd.Ident(sym.valRef)
14+
def rootImport(sym: () => Symbol)(implicit ctx: Context) = {
1615
val selectors = untpd.Ident(nme.WILDCARD) :: Nil
17-
val imp = tpd.Import(expr, selectors)
16+
def expr = tpd.Ident(sym().valRef)
17+
def imp = tpd.Import(expr, selectors)
1818
new ImportInfo(imp.symbol, selectors, isRootImport = true)
1919
}
2020
}
@@ -25,7 +25,9 @@ object ImportInfo {
2525
* @param rootImport true if this is one of the implicit imports of scala, java.lang
2626
* or Predef in the start context, false otherwise.
2727
*/
28-
class ImportInfo(val sym: Symbol, val selectors: List[untpd.Tree], val isRootImport: Boolean = false)(implicit ctx: Context) {
28+
class ImportInfo(symf: => Symbol, val selectors: List[untpd.Tree], val isRootImport: Boolean = false)(implicit ctx: Context) {
29+
30+
lazy val sym = symf
2931

3032
/** The (TermRef) type of the qualifier of the import clause */
3133
def site(implicit ctx: Context): Type = {

0 commit comments

Comments
 (0)