diff options
author | Dmitry Petrashko <dark@d-d.me> | 2016-07-15 13:18:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-15 13:18:46 +0200 |
commit | 18a1c206295fc85c795da48b3e737b88a2bb56e5 (patch) | |
tree | 9bf09c5ffd0360051ef10934be67ec2cd6704468 | |
parent | 409c6c30c8496529aace68967acccf88850145da (diff) | |
parent | 66847062f37a4a5088e9d3fd2228d2679e334d61 (diff) | |
download | dotty-18a1c206295fc85c795da48b3e737b88a2bb56e5.tar.gz dotty-18a1c206295fc85c795da48b3e737b88a2bb56e5.tar.bz2 dotty-18a1c206295fc85c795da48b3e737b88a2bb56e5.zip |
Merge pull request #1334 from dotty-jvican/implement-no-predef-no-import
Implement -Yno-predef and -Yno-imports
-rw-r--r-- | src/dotty/tools/dotc/config/ScalaSettings.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Definitions.scala | 19 | ||||
-rw-r--r-- | test/dotc/tests.scala | 4 | ||||
-rw-r--r-- | tests/neg/customArgs/noimports.scala | 3 | ||||
-rw-r--r-- | tests/neg/customArgs/noimports2.scala | 3 | ||||
-rw-r--r-- | tests/neg/customArgs/nopredef.scala | 3 |
6 files changed, 28 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/config/ScalaSettings.scala b/src/dotty/tools/dotc/config/ScalaSettings.scala index bf56a486e..6a5791b8e 100644 --- a/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -127,7 +127,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.") diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala index 8d020a428..8cd810889 100644 --- a/src/dotty/tools/dotc/core/Definitions.scala +++ b/src/dotty/tools/dotc/core/Definitions.scala @@ -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) diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index 4361ccc13..ad4846c18 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -135,6 +135,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() diff --git a/tests/neg/customArgs/noimports.scala b/tests/neg/customArgs/noimports.scala new file mode 100644 index 000000000..6cef8dee8 --- /dev/null +++ b/tests/neg/customArgs/noimports.scala @@ -0,0 +1,3 @@ +object Test { + val t: Int = 1 // error: not found Int +} diff --git a/tests/neg/customArgs/noimports2.scala b/tests/neg/customArgs/noimports2.scala new file mode 100644 index 000000000..b75f1361d --- /dev/null +++ b/tests/neg/customArgs/noimports2.scala @@ -0,0 +1,3 @@ +object Test { + assert("asdf" == "asdf") // error: not found assert +} diff --git a/tests/neg/customArgs/nopredef.scala b/tests/neg/customArgs/nopredef.scala new file mode 100644 index 000000000..b75f1361d --- /dev/null +++ b/tests/neg/customArgs/nopredef.scala @@ -0,0 +1,3 @@ +object Test { + assert("asdf" == "asdf") // error: not found assert +} |