From b5f68b122fd348cc9b7669d1e00f037979bc7500 Mon Sep 17 00:00:00 2001 From: adampauls Date: Wed, 19 Oct 2022 18:56:25 -0700 Subject: [PATCH 1/4] Add -Yimports compiler flag --- .../src/dotty/tools/dotc/config/ScalaSettings.scala | 1 + compiler/src/dotty/tools/dotc/core/Definitions.scala | 10 ++++++++-- compiler/test/dotty/tools/dotc/CompilationTests.scala | 4 ++++ tests/neg-custom-args/noimports-additional.scala | 4 ++++ tests/neg-custom-args/nopredef-additional.scala | 3 +++ tests/neg/missing-import.scala | 3 +++ .../pos-custom-args/multiple-additional-imports.scala | 4 ++++ tests/pos-custom-args/single-additional-import.scala | 1 + 8 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 tests/neg-custom-args/noimports-additional.scala create mode 100644 tests/neg-custom-args/nopredef-additional.scala create mode 100644 tests/neg/missing-import.scala create mode 100644 tests/pos-custom-args/multiple-additional-imports.scala create mode 100644 tests/pos-custom-args/single-additional-import.scala diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index f7743dddda4e..64b8a91e9096 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -281,6 +281,7 @@ private sealed trait YSettings: val Yscala2Unpickler: Setting[String] = StringSetting("-Yscala2-unpickler", "", "Control where we may get Scala 2 symbols from. This is either \"always\", \"never\", or a classpath.", "always") val YnoImports: Setting[Boolean] = BooleanSetting("-Yno-imports", "Compile without importing scala.*, java.lang.*, or Predef.") + val Yimports: Setting[List[String]] = MultiStringSetting("-Yimports", helpArg="", "Custom root imports. If set, none of scala.*, java.lang.*, or Predef.* will be imported unless explicitly included.") val YnoGenericSig: Setting[Boolean] = BooleanSetting("-Yno-generic-signatures", "Suppress generation of generic signatures for Java.") val YnoPredef: Setting[Boolean] = BooleanSetting("-Yno-predef", "Compile without importing Predef.") val Yskip: Setting[List[String]] = PhasesSetting("-Yskip", "Skip") diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 36aaef8e8f47..24440f89e8ff 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -1558,12 +1558,18 @@ class Definitions { private val PredefImportFns: RootRef = RootRef(() => ScalaPredefModule.termRef, isPredef=true) + @tu private lazy val YimportsImportFns: List[RootRef] = ctx.settings.Yimports.value.map { imp => + RootRef(() => requiredPackageRef(imp), isPredef = false) + } + @tu private lazy val JavaRootImportFns: List[RootRef] = - if ctx.settings.YnoImports.value then Nil + if !ctx.settings.Yimports.isDefault then YimportsImportFns + else if ctx.settings.YnoImports.value then Nil else JavaImportFns @tu private lazy val ScalaRootImportFns: List[RootRef] = - if ctx.settings.YnoImports.value then Nil + if !ctx.settings.Yimports.isDefault then YimportsImportFns + else if ctx.settings.YnoImports.value then Nil else if ctx.settings.YnoPredef.value then ScalaImportFns else ScalaImportFns :+ PredefImportFns diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 500cc6cbe17f..ff192d6451c6 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -68,6 +68,8 @@ class CompilationTests { compileFile("tests/pos-custom-args/i10383.scala", defaultOptions.and("-source", "future", "-deprecation", "-Xfatal-warnings")), compileFile("tests/pos-custom-args/i13044.scala", defaultOptions.and("-Xmax-inlines:33")), compileFile("tests/pos-custom-args/jdk-8-app.scala", defaultOptions.and("-release:8")), + compileFile("tests/pos-custom-args/single-additional-import.scala", defaultOptions.and("-Yimports:scala,java.lang,scala.annotation")), + compileFile("tests/pos-custom-args/multiple-additional-imports.scala", defaultOptions.and("-Yimports:scala,java.lang,scala.Predef,scala.annotation,scala.util.matching")), ).checkCompile() } @@ -154,6 +156,8 @@ class CompilationTests { compileFile("tests/neg-custom-args/nopredef.scala", defaultOptions.and("-Yno-predef")), compileFile("tests/neg-custom-args/noimports.scala", defaultOptions.and("-Yno-imports")), compileFile("tests/neg-custom-args/noimports2.scala", defaultOptions.and("-Yno-imports")), + compileFile("tests/neg-custom-args/noimports-additional.scala", defaultOptions.and("-Yimports:scala.annotation,scala.util.matching")), + compileFile("tests/neg-custom-args/nopredef-additional.scala", defaultOptions.and("-Yimports:java.lang,scala.annotation,scala.util.matching")), compileFile("tests/neg-custom-args/i1650.scala", allowDeepSubtypes), compileFile("tests/neg-custom-args/i3882.scala", allowDeepSubtypes), compileFile("tests/neg-custom-args/i4372.scala", allowDeepSubtypes), diff --git a/tests/neg-custom-args/noimports-additional.scala b/tests/neg-custom-args/noimports-additional.scala new file mode 100644 index 000000000000..5d14c5731615 --- /dev/null +++ b/tests/neg-custom-args/noimports-additional.scala @@ -0,0 +1,4 @@ + +class annotation extends Annotation +val s: String = "str" // error +val regex: Regex = new Regex("str") \ No newline at end of file diff --git a/tests/neg-custom-args/nopredef-additional.scala b/tests/neg-custom-args/nopredef-additional.scala new file mode 100644 index 000000000000..9f4531b17ec3 --- /dev/null +++ b/tests/neg-custom-args/nopredef-additional.scala @@ -0,0 +1,3 @@ +class annotation extends Annotation +val s: String = "str" +val regex: Regex = s.r // error \ No newline at end of file diff --git a/tests/neg/missing-import.scala b/tests/neg/missing-import.scala new file mode 100644 index 000000000000..486dd3bfe5a5 --- /dev/null +++ b/tests/neg/missing-import.scala @@ -0,0 +1,3 @@ +class annotation extends Annotation // error +val s: String = "str" +val regex: Regex = s.r // error \ No newline at end of file diff --git a/tests/pos-custom-args/multiple-additional-imports.scala b/tests/pos-custom-args/multiple-additional-imports.scala new file mode 100644 index 000000000000..474f3b9a1661 --- /dev/null +++ b/tests/pos-custom-args/multiple-additional-imports.scala @@ -0,0 +1,4 @@ + +class annotation extends Annotation +val s: String = "str" +val regex: Regex = s.r \ No newline at end of file diff --git a/tests/pos-custom-args/single-additional-import.scala b/tests/pos-custom-args/single-additional-import.scala new file mode 100644 index 000000000000..ef0780dc2302 --- /dev/null +++ b/tests/pos-custom-args/single-additional-import.scala @@ -0,0 +1 @@ +class annotation extends Annotation \ No newline at end of file From ee168c62fb7d2865c9656144d0ce2bbcbd6b1f1f Mon Sep 17 00:00:00 2001 From: adampauls Date: Mon, 24 Oct 2022 21:02:25 -0700 Subject: [PATCH 2/4] Move to comment-based command line arg tests --- compiler/test/dotty/tools/dotc/CompilationTests.scala | 7 ------- tests/neg-custom-args/nopredef.scala | 3 --- tests/{neg-custom-args => neg}/noimports-additional.scala | 2 +- tests/{neg-custom-args => neg}/noimports.scala | 1 + tests/{neg-custom-args => neg}/noimports2.scala | 1 + tests/{neg-custom-args => neg}/nopredef-additional.scala | 1 + tests/neg/nopredef.scala | 2 +- tests/pos-custom-args/multiple-additional-imports.scala | 4 ---- tests/pos-custom-args/single-additional-import.scala | 1 - tests/pos/multiple-additional-imports.scala | 5 +++++ tests/pos/single-additional-import.scala | 2 ++ 11 files changed, 12 insertions(+), 17 deletions(-) delete mode 100644 tests/neg-custom-args/nopredef.scala rename tests/{neg-custom-args => neg}/noimports-additional.scala (58%) rename tests/{neg-custom-args => neg}/noimports.scala (70%) rename tests/{neg-custom-args => neg}/noimports2.scala (74%) rename tests/{neg-custom-args => neg}/nopredef-additional.scala (52%) delete mode 100644 tests/pos-custom-args/multiple-additional-imports.scala delete mode 100644 tests/pos-custom-args/single-additional-import.scala create mode 100644 tests/pos/multiple-additional-imports.scala create mode 100644 tests/pos/single-additional-import.scala diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index ff192d6451c6..20daa2d24406 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -68,8 +68,6 @@ class CompilationTests { compileFile("tests/pos-custom-args/i10383.scala", defaultOptions.and("-source", "future", "-deprecation", "-Xfatal-warnings")), compileFile("tests/pos-custom-args/i13044.scala", defaultOptions.and("-Xmax-inlines:33")), compileFile("tests/pos-custom-args/jdk-8-app.scala", defaultOptions.and("-release:8")), - compileFile("tests/pos-custom-args/single-additional-import.scala", defaultOptions.and("-Yimports:scala,java.lang,scala.annotation")), - compileFile("tests/pos-custom-args/multiple-additional-imports.scala", defaultOptions.and("-Yimports:scala,java.lang,scala.Predef,scala.annotation,scala.util.matching")), ).checkCompile() } @@ -153,11 +151,6 @@ class CompilationTests { compileFile("tests/neg-custom-args/ovlazy.scala", scala2CompatMode.and("-Xfatal-warnings")), compileFile("tests/neg-custom-args/newline-braces.scala", scala2CompatMode.and("-Xfatal-warnings")), compileFile("tests/neg-custom-args/autoTuplingTest.scala", defaultOptions.andLanguageFeature("noAutoTupling")), - compileFile("tests/neg-custom-args/nopredef.scala", defaultOptions.and("-Yno-predef")), - compileFile("tests/neg-custom-args/noimports.scala", defaultOptions.and("-Yno-imports")), - compileFile("tests/neg-custom-args/noimports2.scala", defaultOptions.and("-Yno-imports")), - compileFile("tests/neg-custom-args/noimports-additional.scala", defaultOptions.and("-Yimports:scala.annotation,scala.util.matching")), - compileFile("tests/neg-custom-args/nopredef-additional.scala", defaultOptions.and("-Yimports:java.lang,scala.annotation,scala.util.matching")), compileFile("tests/neg-custom-args/i1650.scala", allowDeepSubtypes), compileFile("tests/neg-custom-args/i3882.scala", allowDeepSubtypes), compileFile("tests/neg-custom-args/i4372.scala", allowDeepSubtypes), diff --git a/tests/neg-custom-args/nopredef.scala b/tests/neg-custom-args/nopredef.scala deleted file mode 100644 index b75f1361ddb9..000000000000 --- a/tests/neg-custom-args/nopredef.scala +++ /dev/null @@ -1,3 +0,0 @@ -object Test { - assert("asdf" == "asdf") // error: not found assert -} diff --git a/tests/neg-custom-args/noimports-additional.scala b/tests/neg/noimports-additional.scala similarity index 58% rename from tests/neg-custom-args/noimports-additional.scala rename to tests/neg/noimports-additional.scala index 5d14c5731615..7606f244c871 100644 --- a/tests/neg-custom-args/noimports-additional.scala +++ b/tests/neg/noimports-additional.scala @@ -1,4 +1,4 @@ - +// scalac: -Yno-imports -Yimports:scala.annotation,scala.util.matching class annotation extends Annotation val s: String = "str" // error val regex: Regex = new Regex("str") \ No newline at end of file diff --git a/tests/neg-custom-args/noimports.scala b/tests/neg/noimports.scala similarity index 70% rename from tests/neg-custom-args/noimports.scala rename to tests/neg/noimports.scala index 6cef8dee8843..720d111757cd 100644 --- a/tests/neg-custom-args/noimports.scala +++ b/tests/neg/noimports.scala @@ -1,3 +1,4 @@ +// scalac: -Yno-imports object Test { val t: Int = 1 // error: not found Int } diff --git a/tests/neg-custom-args/noimports2.scala b/tests/neg/noimports2.scala similarity index 74% rename from tests/neg-custom-args/noimports2.scala rename to tests/neg/noimports2.scala index b75f1361ddb9..deee773c35c6 100644 --- a/tests/neg-custom-args/noimports2.scala +++ b/tests/neg/noimports2.scala @@ -1,3 +1,4 @@ +// scalac: -Yno-imports object Test { assert("asdf" == "asdf") // error: not found assert } diff --git a/tests/neg-custom-args/nopredef-additional.scala b/tests/neg/nopredef-additional.scala similarity index 52% rename from tests/neg-custom-args/nopredef-additional.scala rename to tests/neg/nopredef-additional.scala index 9f4531b17ec3..8b67231130a5 100644 --- a/tests/neg-custom-args/nopredef-additional.scala +++ b/tests/neg/nopredef-additional.scala @@ -1,3 +1,4 @@ +// scalac: -Yno-predef -Yimports:java.lang,scala.annotation,scala.util.matching class annotation extends Annotation val s: String = "str" val regex: Regex = s.r // error \ No newline at end of file diff --git a/tests/neg/nopredef.scala b/tests/neg/nopredef.scala index 0a22e200805a..40fe825fb1c1 100644 --- a/tests/neg/nopredef.scala +++ b/tests/neg/nopredef.scala @@ -1,5 +1,5 @@ +// scalac: -Yno-predef import Predef.{assert as _} - object Test { assert("asdf" == "asdf") // error: not found assert } diff --git a/tests/pos-custom-args/multiple-additional-imports.scala b/tests/pos-custom-args/multiple-additional-imports.scala deleted file mode 100644 index 474f3b9a1661..000000000000 --- a/tests/pos-custom-args/multiple-additional-imports.scala +++ /dev/null @@ -1,4 +0,0 @@ - -class annotation extends Annotation -val s: String = "str" -val regex: Regex = s.r \ No newline at end of file diff --git a/tests/pos-custom-args/single-additional-import.scala b/tests/pos-custom-args/single-additional-import.scala deleted file mode 100644 index ef0780dc2302..000000000000 --- a/tests/pos-custom-args/single-additional-import.scala +++ /dev/null @@ -1 +0,0 @@ -class annotation extends Annotation \ No newline at end of file diff --git a/tests/pos/multiple-additional-imports.scala b/tests/pos/multiple-additional-imports.scala new file mode 100644 index 000000000000..cd991ddf6ca2 --- /dev/null +++ b/tests/pos/multiple-additional-imports.scala @@ -0,0 +1,5 @@ +// scalac: -Yimports:scala,java.lang,scala.Predef,scala.annotation,scala.util.matching + +class annotation extends Annotation +val s: String = "str" +val regex: Regex = s.r \ No newline at end of file diff --git a/tests/pos/single-additional-import.scala b/tests/pos/single-additional-import.scala new file mode 100644 index 000000000000..a1cf734b4254 --- /dev/null +++ b/tests/pos/single-additional-import.scala @@ -0,0 +1,2 @@ +// scalac: -Yimports:scala.annotation +class annotation extends Annotation \ No newline at end of file From 3259ee846b3847df6d4875bb4e033955ba3dc42e Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 24 Nov 2022 14:42:36 +0000 Subject: [PATCH 3/4] Drop -Yimports & -Yno-imports from affecting java root imports Matching Scala 2 behaviour. --- compiler/src/dotty/tools/dotc/core/Definitions.scala | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 24440f89e8ff..30963f509ceb 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -1562,10 +1562,7 @@ class Definitions { RootRef(() => requiredPackageRef(imp), isPredef = false) } - @tu private lazy val JavaRootImportFns: List[RootRef] = - if !ctx.settings.Yimports.isDefault then YimportsImportFns - else if ctx.settings.YnoImports.value then Nil - else JavaImportFns + @tu private lazy val JavaRootImportFns: List[RootRef] = JavaImportFns @tu private lazy val ScalaRootImportFns: List[RootRef] = if !ctx.settings.Yimports.isDefault then YimportsImportFns From e0e61bd22a1351433ef45ac1661cca1c59361fbd Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 24 Nov 2022 14:43:36 +0000 Subject: [PATCH 4/4] Match Scala 2 -Yimports behaviour And add its tests. --- .../src/dotty/tools/dotc/core/Definitions.scala | 10 ++++++++-- tests/neg/missing-import.scala | 2 +- tests/neg/noimports-additional.scala | 2 +- tests/neg/nopredef-additional.scala | 2 +- tests/neg/nopredef.scala | 1 - tests/neg/unimport-Predef-assert.scala | 5 +++++ tests/neg/yimports-custom.check | 7 +++++++ tests/neg/yimports-custom/C_2.scala | 6 ++++++ tests/neg/yimports-custom/minidef_1.scala | 7 +++++++ tests/neg/yimports-nojava.check | 12 ++++++++++++ tests/neg/yimports-nojava.scala | 7 +++++++ tests/neg/yimports-nosuch.check | 2 ++ tests/neg/yimports-nosuch.scala | 5 +++++ tests/neg/yimports-order.check | 16 ++++++++++++++++ tests/neg/yimports-order.scala | 13 +++++++++++++ tests/neg/yimports-predef.check | 4 ++++ tests/neg/yimports-predef.scala | 7 +++++++ tests/neg/yimports-stable.check | 14 ++++++++++++++ tests/neg/yimports-stable/C_2.scala | 7 +++++++ tests/neg/yimports-stable/minidef_1.scala | 11 +++++++++++ tests/pending/neg/yimports-custom-b.check | 10 ++++++++++ tests/pending/neg/yimports-custom-b/C_2.scala | 10 ++++++++++ .../neg/yimports-custom-b/minidef_1.scala | 8 ++++++++ tests/pending/neg/yimports-masked.check | 10 ++++++++++ tests/pending/neg/yimports-masked/C_2.scala | 14 ++++++++++++++ .../pending/neg/yimports-masked/minidef_1.scala | 7 +++++++ tests/pos/multiple-additional-imports.scala | 2 +- tests/pos/single-additional-import.scala | 2 +- 28 files changed, 195 insertions(+), 8 deletions(-) create mode 100644 tests/neg/unimport-Predef-assert.scala create mode 100644 tests/neg/yimports-custom.check create mode 100644 tests/neg/yimports-custom/C_2.scala create mode 100644 tests/neg/yimports-custom/minidef_1.scala create mode 100644 tests/neg/yimports-nojava.check create mode 100644 tests/neg/yimports-nojava.scala create mode 100644 tests/neg/yimports-nosuch.check create mode 100644 tests/neg/yimports-nosuch.scala create mode 100644 tests/neg/yimports-order.check create mode 100644 tests/neg/yimports-order.scala create mode 100644 tests/neg/yimports-predef.check create mode 100644 tests/neg/yimports-predef.scala create mode 100644 tests/neg/yimports-stable.check create mode 100644 tests/neg/yimports-stable/C_2.scala create mode 100644 tests/neg/yimports-stable/minidef_1.scala create mode 100644 tests/pending/neg/yimports-custom-b.check create mode 100644 tests/pending/neg/yimports-custom-b/C_2.scala create mode 100644 tests/pending/neg/yimports-custom-b/minidef_1.scala create mode 100644 tests/pending/neg/yimports-masked.check create mode 100644 tests/pending/neg/yimports-masked/C_2.scala create mode 100644 tests/pending/neg/yimports-masked/minidef_1.scala diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 30963f509ceb..bad796df2bd5 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -1558,8 +1558,14 @@ class Definitions { private val PredefImportFns: RootRef = RootRef(() => ScalaPredefModule.termRef, isPredef=true) - @tu private lazy val YimportsImportFns: List[RootRef] = ctx.settings.Yimports.value.map { imp => - RootRef(() => requiredPackageRef(imp), isPredef = false) + @tu private lazy val YimportsImportFns: List[RootRef] = ctx.settings.Yimports.value.map { name => + val denot = + getModuleIfDefined(name).suchThat(_.is(Module)) `orElse` + getPackageClassIfDefined(name).suchThat(_.is(Package)) + if !denot.exists then + report.error(s"error: bad preamble import $name") + val termRef = denot.symbol.termRef + RootRef(() => termRef) } @tu private lazy val JavaRootImportFns: List[RootRef] = JavaImportFns diff --git a/tests/neg/missing-import.scala b/tests/neg/missing-import.scala index 486dd3bfe5a5..8af26030435a 100644 --- a/tests/neg/missing-import.scala +++ b/tests/neg/missing-import.scala @@ -1,3 +1,3 @@ class annotation extends Annotation // error val s: String = "str" -val regex: Regex = s.r // error \ No newline at end of file +val regex: Regex = s.r // error diff --git a/tests/neg/noimports-additional.scala b/tests/neg/noimports-additional.scala index 7606f244c871..e726db5b9b0a 100644 --- a/tests/neg/noimports-additional.scala +++ b/tests/neg/noimports-additional.scala @@ -1,4 +1,4 @@ // scalac: -Yno-imports -Yimports:scala.annotation,scala.util.matching class annotation extends Annotation val s: String = "str" // error -val regex: Regex = new Regex("str") \ No newline at end of file +val regex: Regex = new Regex("str") diff --git a/tests/neg/nopredef-additional.scala b/tests/neg/nopredef-additional.scala index 8b67231130a5..0b6a71ca7c53 100644 --- a/tests/neg/nopredef-additional.scala +++ b/tests/neg/nopredef-additional.scala @@ -1,4 +1,4 @@ // scalac: -Yno-predef -Yimports:java.lang,scala.annotation,scala.util.matching class annotation extends Annotation val s: String = "str" -val regex: Regex = s.r // error \ No newline at end of file +val regex: Regex = s.r // error diff --git a/tests/neg/nopredef.scala b/tests/neg/nopredef.scala index 40fe825fb1c1..fa9a344772a6 100644 --- a/tests/neg/nopredef.scala +++ b/tests/neg/nopredef.scala @@ -1,5 +1,4 @@ // scalac: -Yno-predef -import Predef.{assert as _} object Test { assert("asdf" == "asdf") // error: not found assert } diff --git a/tests/neg/unimport-Predef-assert.scala b/tests/neg/unimport-Predef-assert.scala new file mode 100644 index 000000000000..0a22e200805a --- /dev/null +++ b/tests/neg/unimport-Predef-assert.scala @@ -0,0 +1,5 @@ +import Predef.{assert as _} + +object Test { + assert("asdf" == "asdf") // error: not found assert +} diff --git a/tests/neg/yimports-custom.check b/tests/neg/yimports-custom.check new file mode 100644 index 000000000000..6ed2eb8b1df3 --- /dev/null +++ b/tests/neg/yimports-custom.check @@ -0,0 +1,7 @@ + +-- [E006] Not Found Error: tests/neg/yimports-custom/C_2.scala:5:16 ---------------------------------------------------- +5 | def greet() = println("hello, world!") // error + | ^^^^^^^ + | Not found: println + | + | longer explanation available when compiling with `-explain` diff --git a/tests/neg/yimports-custom/C_2.scala b/tests/neg/yimports-custom/C_2.scala new file mode 100644 index 000000000000..6ba25ad2963c --- /dev/null +++ b/tests/neg/yimports-custom/C_2.scala @@ -0,0 +1,6 @@ +// scalac: -Yimports:hello.world.minidef + +class C { + val v: Numb = Magic + def greet() = println("hello, world!") // error +} diff --git a/tests/neg/yimports-custom/minidef_1.scala b/tests/neg/yimports-custom/minidef_1.scala new file mode 100644 index 000000000000..5d18d0a39584 --- /dev/null +++ b/tests/neg/yimports-custom/minidef_1.scala @@ -0,0 +1,7 @@ + +package hello.world + +object minidef { + type Numb = Int + final val Magic = 42 +} diff --git a/tests/neg/yimports-nojava.check b/tests/neg/yimports-nojava.check new file mode 100644 index 000000000000..8aef6786ca21 --- /dev/null +++ b/tests/neg/yimports-nojava.check @@ -0,0 +1,12 @@ +-- [E006] Not Found Error: tests/neg/yimports-nojava.scala:5:16 -------------------------------------------------------- +5 | def g() = new Integer(42) // error + | ^^^^^^^ + | Not found: type Integer + | + | longer explanation available when compiling with `-explain` +-- [E006] Not Found Error: tests/neg/yimports-nojava.scala:6:16 -------------------------------------------------------- +6 | def sleep() = Thread.sleep(42000L) // error + | ^^^^^^ + | Not found: Thread + | + | longer explanation available when compiling with `-explain` diff --git a/tests/neg/yimports-nojava.scala b/tests/neg/yimports-nojava.scala new file mode 100644 index 000000000000..35233e37a775 --- /dev/null +++ b/tests/neg/yimports-nojava.scala @@ -0,0 +1,7 @@ +// scalac: -Yimports:scala,scala.Predef + +trait T { + def f() = println("hello, world!") + def g() = new Integer(42) // error + def sleep() = Thread.sleep(42000L) // error +} diff --git a/tests/neg/yimports-nosuch.check b/tests/neg/yimports-nosuch.check new file mode 100644 index 000000000000..5a77d7f8d016 --- /dev/null +++ b/tests/neg/yimports-nosuch.check @@ -0,0 +1,2 @@ +error: bad preamble import skala +error: bad preamble import scala.Predeff diff --git a/tests/neg/yimports-nosuch.scala b/tests/neg/yimports-nosuch.scala new file mode 100644 index 000000000000..431daf39a180 --- /dev/null +++ b/tests/neg/yimports-nosuch.scala @@ -0,0 +1,5 @@ +// scalac: -Yimports:skala,scala.Predeff +// +class C +// nopos-error +// nopos-error diff --git a/tests/neg/yimports-order.check b/tests/neg/yimports-order.check new file mode 100644 index 000000000000..b49503f75e01 --- /dev/null +++ b/tests/neg/yimports-order.check @@ -0,0 +1,16 @@ +-- [E006] Not Found Error: tests/neg/yimports-order.scala:9:16 --------------------------------------------------------- +9 | def f() = Map("hello" -> "world") // error // error + | ^^^ + | Not found: Map + | + | longer explanation available when compiling with `-explain` +-- [E008] Not Found Error: tests/neg/yimports-order.scala:9:28 --------------------------------------------------------- +9 | def f() = Map("hello" -> "world") // error // error + | ^^^^^^^^^^ + | value -> is not a member of String +-- [E006] Not Found Error: tests/neg/yimports-order.scala:10:16 -------------------------------------------------------- +10 | def g() = println(f()) // error + | ^^^^^^^ + | Not found: println + | + | longer explanation available when compiling with `-explain` diff --git a/tests/neg/yimports-order.scala b/tests/neg/yimports-order.scala new file mode 100644 index 000000000000..9cba91385b8a --- /dev/null +++ b/tests/neg/yimports-order.scala @@ -0,0 +1,13 @@ + +package top { + package middle { + class C { + def c() = println("hello, world") + } + import Predef.{Map => _} + object Test { + def f() = Map("hello" -> "world") // error // error + def g() = println(f()) // error + } + } +} diff --git a/tests/neg/yimports-predef.check b/tests/neg/yimports-predef.check new file mode 100644 index 000000000000..eb8881e04223 --- /dev/null +++ b/tests/neg/yimports-predef.check @@ -0,0 +1,4 @@ +-- [E008] Not Found Error: tests/neg/yimports-predef.scala:6:21 -------------------------------------------------------- +6 | def f[A](x: A) = x + 42 // error + | ^^^ + | value + is not a member of A diff --git a/tests/neg/yimports-predef.scala b/tests/neg/yimports-predef.scala new file mode 100644 index 000000000000..8bfe89b08cd8 --- /dev/null +++ b/tests/neg/yimports-predef.scala @@ -0,0 +1,7 @@ +// scalac: -Yimports:scala,scala.Predef +// +import Predef.{any2stringadd => _, _} + +class classic { + def f[A](x: A) = x + 42 // error +} diff --git a/tests/neg/yimports-stable.check b/tests/neg/yimports-stable.check new file mode 100644 index 000000000000..c5bfd914ae07 --- /dev/null +++ b/tests/neg/yimports-stable.check @@ -0,0 +1,14 @@ + +error: bad preamble import hello.world.potions +-- [E006] Not Found Error: tests/neg/yimports-stable/C_2.scala:4:9 ----------------------------------------------------- +4 | val v: Numb = magic // error // error + | ^^^^ + | Not found: type Numb + | + | longer explanation available when compiling with `-explain` +-- [E006] Not Found Error: tests/neg/yimports-stable/C_2.scala:4:16 ---------------------------------------------------- +4 | val v: Numb = magic // error // error + | ^^^^^ + | Not found: magic + | + | longer explanation available when compiling with `-explain` diff --git a/tests/neg/yimports-stable/C_2.scala b/tests/neg/yimports-stable/C_2.scala new file mode 100644 index 000000000000..0b97775f1a01 --- /dev/null +++ b/tests/neg/yimports-stable/C_2.scala @@ -0,0 +1,7 @@ +// scalac: -Yimports:scala,scala.Predef,hello.world.potions +// +class C { + val v: Numb = magic // error // error + def greet() = println("hello, world!") +} +// nopos-error diff --git a/tests/neg/yimports-stable/minidef_1.scala b/tests/neg/yimports-stable/minidef_1.scala new file mode 100644 index 000000000000..b3ea7445df24 --- /dev/null +++ b/tests/neg/yimports-stable/minidef_1.scala @@ -0,0 +1,11 @@ + +package hello + +trait stuff { + type Numb = Int + val magic = 42 +} + +object world { + val potions = new stuff {} +} diff --git a/tests/pending/neg/yimports-custom-b.check b/tests/pending/neg/yimports-custom-b.check new file mode 100644 index 000000000000..d046a1d8f6cc --- /dev/null +++ b/tests/pending/neg/yimports-custom-b.check @@ -0,0 +1,10 @@ + +C_2.scala:8: error: not found: type Numb + val v: Numb = Answer + ^ +-- [E006] Not Found Error: tests/neg/yimports-custom-b/C_2.scala:9:16 -------------------------------------------------- +9 | def greet() = println("hello, world!") // error + | ^^^^^^^ + | Not found: println + | + | longer explanation available when compiling with `-explain` diff --git a/tests/pending/neg/yimports-custom-b/C_2.scala b/tests/pending/neg/yimports-custom-b/C_2.scala new file mode 100644 index 000000000000..8da798e80b0d --- /dev/null +++ b/tests/pending/neg/yimports-custom-b/C_2.scala @@ -0,0 +1,10 @@ +// scalac: -Yimports:hello.world.minidef + +import hello.{world => hw} +import hw.minidef.{Magic => Answer} + +// Finds the answer, but dumb to forget Numb +class C { + val v: Numb = Answer // error + def greet() = println("hello, world!") // error +} diff --git a/tests/pending/neg/yimports-custom-b/minidef_1.scala b/tests/pending/neg/yimports-custom-b/minidef_1.scala new file mode 100644 index 000000000000..befc137b6ab6 --- /dev/null +++ b/tests/pending/neg/yimports-custom-b/minidef_1.scala @@ -0,0 +1,8 @@ +// scalac: -Yimports:scala + +package hello.world + +object minidef { + type Numb = Int + final val Magic = 42 +} diff --git a/tests/pending/neg/yimports-masked.check b/tests/pending/neg/yimports-masked.check new file mode 100644 index 000000000000..ae715313392a --- /dev/null +++ b/tests/pending/neg/yimports-masked.check @@ -0,0 +1,10 @@ + +C_2.scala:11: error: not found: type Numb + val v: Numb = Answer + ^ +-- [E006] Not Found Error: tests/neg/yimports-masked/C_2.scala:12:18 --------------------------------------------------- +12 | def greet() = println("hello, world!") // error + | ^^^^^^^ + | Not found: println + | + | longer explanation available when compiling with `-explain` diff --git a/tests/pending/neg/yimports-masked/C_2.scala b/tests/pending/neg/yimports-masked/C_2.scala new file mode 100644 index 000000000000..1b6c736bad7b --- /dev/null +++ b/tests/pending/neg/yimports-masked/C_2.scala @@ -0,0 +1,14 @@ +// scalac: -Yimports:scala,hello.world.minidef + +// import at top level or top of package disables implicit import. +// the import can appear at any statement position, here, end of package. +// Update: with new trick, the import has to be completed before usages. + +import hello.world.minidef.{Magic => Answer} + +package p { + class C { + val v: Numb = Answer // error + def greet() = println("hello, world!") // error + } +} diff --git a/tests/pending/neg/yimports-masked/minidef_1.scala b/tests/pending/neg/yimports-masked/minidef_1.scala new file mode 100644 index 000000000000..5d18d0a39584 --- /dev/null +++ b/tests/pending/neg/yimports-masked/minidef_1.scala @@ -0,0 +1,7 @@ + +package hello.world + +object minidef { + type Numb = Int + final val Magic = 42 +} diff --git a/tests/pos/multiple-additional-imports.scala b/tests/pos/multiple-additional-imports.scala index cd991ddf6ca2..a86c7e8fc342 100644 --- a/tests/pos/multiple-additional-imports.scala +++ b/tests/pos/multiple-additional-imports.scala @@ -2,4 +2,4 @@ class annotation extends Annotation val s: String = "str" -val regex: Regex = s.r \ No newline at end of file +val regex: Regex = s.r diff --git a/tests/pos/single-additional-import.scala b/tests/pos/single-additional-import.scala index a1cf734b4254..d8ca5b54e05e 100644 --- a/tests/pos/single-additional-import.scala +++ b/tests/pos/single-additional-import.scala @@ -1,2 +1,2 @@ // scalac: -Yimports:scala.annotation -class annotation extends Annotation \ No newline at end of file +class annotation extends Annotation