diff options
author | jvican <jorgevc@fastmail.es> | 2016-06-27 23:20:03 +0200 |
---|---|---|
committer | jvican <jorgevc@fastmail.es> | 2016-06-29 00:08:56 +0200 |
commit | 66847062f37a4a5088e9d3fd2228d2679e334d61 (patch) | |
tree | 34ae75ac7cece5f844cb98d79e27973e790f17d5 | |
parent | c7d1826cf0456e5efad5cb66ae06e7273c8a8e2a (diff) | |
download | dotty-66847062f37a4a5088e9d3fd2228d2679e334d61.tar.gz dotty-66847062f37a4a5088e9d3fd2228d2679e334d61.tar.bz2 dotty-66847062f37a4a5088e9d3fd2228d2679e334d61.zip |
Implement -Yno-predef and -Yno-imports
* Implement flags -Yno-predef and -Yno-imports
* Add unit tests for both
-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 74ff76444..229010695 100644 --- a/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -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.") diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala index 5cb373cfd..87d46f823 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 bac443735..04d88a9f6 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -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() 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 +} |