Skip to content

Allow to compile root import classes without special option. #539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@ class Compiler {
.setMode(Mode.ImplicitsEnabled)
.setTyperState(new MutableTyperState(ctx.typerState, new ConsoleReporter()(ctx), isCommittable = true))
ctx.definitions.init(start) // set context of definitions to start
start.setRunInfo(new RunInfo(start))
def addImport(ctx: Context, sym: Symbol) =
ctx.fresh.setImportInfo(ImportInfo.rootImport(sym)(ctx))
if (ctx.settings.YnoImports.value) start
else (start /: defn.RootImports)(addImport)
def addImport(ctx: Context, symf: () => Symbol) =
ctx.fresh.setImportInfo(ImportInfo.rootImport(symf)(ctx))
(start.setRunInfo(new RunInfo(start)) /: defn.RootImportFns)(addImport)
}

def reset()(implicit ctx: Context): Unit = {
Expand Down
4 changes: 3 additions & 1 deletion src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,9 @@ class Definitions {

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

lazy val RootImports = List[Symbol](JavaLangPackageVal, ScalaPackageVal, ScalaPredefModule, DottyPredefModule)
val RootImportFns = List[() => Symbol](() => JavaLangPackageVal, () => ScalaPackageVal, () => ScalaPredefModule, () => DottyPredefModule)

lazy val RootImports = RootImportFns.map(_())

def isTupleType(tp: Type)(implicit ctx: Context) = {
val arity = tp.dealias.argInfos.length
Expand Down
10 changes: 6 additions & 4 deletions src/dotty/tools/dotc/typer/ImportInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import Decorators.StringInterpolators

object ImportInfo {
/** The import info for a root import from given symbol `sym` */
def rootImport(sym: Symbol)(implicit ctx: Context) = {
val expr = tpd.Ident(sym.valRef)
def rootImport(sym: () => Symbol)(implicit ctx: Context) = {
val selectors = untpd.Ident(nme.WILDCARD) :: Nil
val imp = tpd.Import(expr, selectors)
def expr = tpd.Ident(sym().valRef)
def imp = tpd.Import(expr, selectors)
new ImportInfo(imp.symbol, selectors, isRootImport = true)
}
}
Expand All @@ -25,7 +25,9 @@ object ImportInfo {
* @param rootImport true if this is one of the implicit imports of scala, java.lang
* or Predef in the start context, false otherwise.
*/
class ImportInfo(val sym: Symbol, val selectors: List[untpd.Tree], val isRootImport: Boolean = false)(implicit ctx: Context) {
class ImportInfo(symf: => Symbol, val selectors: List[untpd.Tree], val isRootImport: Boolean = false)(implicit ctx: Context) {

lazy val sym = symf

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