Skip to content

Implement -Yno-predef and -Yno-imports #1334

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
Jul 15, 2016
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
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class ScalaSettings extends Settings.SettingGroup {
val Ylogcp = BooleanSetting("-Ylog-classpath", "Output information about what classpath is being applied.")
val Ynogenericsig = BooleanSetting("-Yno-generic-signatures", "Suppress generation of generic signatures for Java.")
val YnoImports = BooleanSetting("-Yno-imports", "Compile without importing scala.*, java.lang.*, or Predef.")
val nopredef = BooleanSetting("-Yno-predef", "Compile without importing Predef.")
val YnoPredef = BooleanSetting("-Yno-predef", "Compile without importing Predef.")
val noAdaptedArgs = BooleanSetting("-Yno-adapted-args", "Do not adapt an argument list (either by inserting () or creating a tuple) to match the receiver.")
val selfInAnnots = BooleanSetting("-Yself-in-annots", "Include a \"self\" identifier inside of annotations.")
val Yshowtrees = BooleanSetting("-Yshow-trees", "(Requires -Xprint:) Print detailed ASTs in formatted form.")
Expand Down
19 changes: 14 additions & 5 deletions src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -627,15 +627,24 @@ class Definitions {
def isTupleClass(cls: Symbol) = isVarArityClass(cls, tpnme.Tuple)
def isProductClass(cls: Symbol) = isVarArityClass(cls, tpnme.Product)

val RootImportFns = List[() => TermRef](
() => JavaLangPackageVal.termRef,
() => ScalaPackageVal.termRef,
val StaticRootImportFns = List[() => TermRef](
() => JavaLangPackageVal.termRef,
() => ScalaPackageVal.termRef
)

val PredefImportFns = List[() => TermRef](
() => ScalaPredefModuleRef,
() => DottyPredefModuleRef)
() => DottyPredefModuleRef
)

lazy val RootImportFns =
if (ctx.settings.YnoImports.value) List.empty[() => TermRef]
else if (ctx.settings.YnoPredef.value) StaticRootImportFns
else StaticRootImportFns ++ PredefImportFns

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

/** `Modules whose members are in the default namespace and their module classes */
/** Modules whose members are in the default namespace and their module classes */
lazy val UnqualifiedOwnerTypes: Set[NamedType] =
RootImportTypes.toSet[NamedType] ++ RootImportTypes.map(_.symbol.moduleClass.typeRef)

Expand Down
4 changes: 4 additions & 0 deletions test/dotc/tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ class tests extends CompilerTest {
@Test def neg_tailcall2 = compileFile(negTailcallDir, "tailrec-2")
@Test def neg_tailcall3 = compileFile(negTailcallDir, "tailrec-3")

@Test def neg_nopredef = compileFile(negCustomArgs, "nopredef", List("-Yno-predef"))
@Test def neg_noimports = compileFile(negCustomArgs, "noimports", List("-Yno-imports"))
@Test def neg_noimpots2 = compileFile(negCustomArgs, "noimports2", List("-Yno-imports"))

@Test def run_all = runFiles(runDir)

val stdlibFiles = Source.fromFile("./test/dotc/scala-collections.whitelist", "UTF8").getLines()
Expand Down
3 changes: 3 additions & 0 deletions tests/neg/customArgs/noimports.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test {
val t: Int = 1 // error: not found Int
}
3 changes: 3 additions & 0 deletions tests/neg/customArgs/noimports2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test {
assert("asdf" == "asdf") // error: not found assert
}
3 changes: 3 additions & 0 deletions tests/neg/customArgs/nopredef.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test {
assert("asdf" == "asdf") // error: not found assert
}