diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 0c44a640ec25..0de723a82159 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -486,7 +486,7 @@ object desugar { // TODO When the Scala library is updated to 2.13.x add the override keyword to this generated method. // (because Product.scala was updated) - def productElemNameMethod = { + def productElemNameMeth = { val methodParam = makeSyntheticParameter(tpt = scalaDot(tpnme.Int)) val paramRef = Ident(methodParam.name) @@ -499,11 +499,11 @@ object desugar { } :+ defaultCase val body = Match(paramRef, patternMatchCases) DefDef(nme.productElementName, Nil, List(List(methodParam)), javaDotLangDot(tpnme.String), body) - .withFlags(Synthetic) + .withFlags(if (defn.isNewCollections) Override | Synthetic else Synthetic) } if (isCaseClass) - productElemNameMethod :: copyMeths ::: enumTagMeths ::: productElemMeths + productElemNameMeth :: copyMeths ::: enumTagMeths ::: productElemMeths else Nil } diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index ca29bfa1bfc6..fd8ae714741c 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -91,9 +91,11 @@ class ScalaSettings extends Settings.SettingGroup { val Ylog: Setting[List[String]] = PhasesSetting("-Ylog", "Log operations during") val YemitTastyInClass: Setting[Boolean] = BooleanSetting("-Yemit-tasty-in-class", "Generate tasty in the .class file and add an empty *.hasTasty file.") val YlogClasspath: Setting[Boolean] = BooleanSetting("-Ylog-classpath", "Output information about what classpath is being applied.") - val YdisableFlatCpCaching: Setting[Boolean] = BooleanSetting("-YdisableFlatCpCaching", "Do not cache flat classpath representation of classpath elements from jars across compiler instances.") + val YdisableFlatCpCaching: Setting[Boolean] = BooleanSetting("-YdisableFlatCpCaching", "Do not cache flat classpath representation of classpath elements from jars across compiler instances.") 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") + // TODO: Remove once we drop support for 2.12 standard library + val YnewCollections: Setting[Boolean] = BooleanSetting("-Ynew-collections", "Inform the compiler that we are using the 2.13 collection library (even if the 2.12 library is on the classpath).") val YnoImports: Setting[Boolean] = BooleanSetting("-Yno-imports", "Compile without importing scala.*, java.lang.*, or Predef.") val YnoInline: Setting[Boolean] = BooleanSetting("-Yno-inline", "Suppress inlining.") diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 8078b5da6e24..ec259c536337 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -396,7 +396,8 @@ class Definitions { def newArrayMethod(implicit ctx: Context): TermSymbol = DottyArraysModule.requiredMethod("newArray") // TODO: Remove once we drop support for 2.12 standard library - private[this] lazy val isNewCollections = ctx.base.staticRef("scala.collection.IterableOnce".toTypeName).exists + lazy val isNewCollections: Boolean = ctx.settings.YnewCollections.value || + ctx.base.staticRef("scala.collection.IterableOnce".toTypeName).exists def getWrapVarargsArrayModule: Symbol = if (isNewCollections) ScalaRuntimeModule else ScalaPredefModule diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index eb838f2b6c8a..2b786bea20c4 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -48,6 +48,7 @@ class CompilationTests extends ParallelTesting { compileFile("tests/pos-special/completeFromSource/Test2.scala", defaultOptions.and("-sourcepath", "tests/pos-special")) + compileFile("tests/pos-special/completeFromSource/Test3.scala", defaultOptions.and("-sourcepath", "tests/pos-special", "-scansource")) + compileFile("tests/pos-special/completeFromSource/nested/Test4.scala", defaultOptions.and("-sourcepath", "tests/pos-special", "-scansource")) + + compileFile("tests/pos-special/repeatedArgs213.scala", defaultOptions.and("-Ynew-collections")) + compileFilesInDir("tests/pos-special/fatal-warnings", defaultOptions.and("-Xfatal-warnings", "-feature")) + compileList( "compileMixed", @@ -162,7 +163,8 @@ class CompilationTests extends ParallelTesting { compileFilesInDir("tests/neg-custom-args/isInstanceOf", allowDeepSubtypes and "-Xfatal-warnings") + compileFile("tests/neg-custom-args/i3627.scala", allowDeepSubtypes) + compileFile("tests/neg-custom-args/matchtype-loop.scala", allowDeepSubtypes) + - compileFile("tests/neg-custom-args/completeFromSource/nested/Test1.scala", defaultOptions.and("-sourcepath", "tests/neg-custom-args", "-scansource")) + compileFile("tests/neg-custom-args/completeFromSource/nested/Test1.scala", defaultOptions.and("-sourcepath", "tests/neg-custom-args", "-scansource")) + + compileFile("tests/neg-custom-args/repeatedArgs213.scala", defaultOptions.and("-Ynew-collections")) }.checkExpectedErrors() // Run tests ----------------------------------------------------------------- diff --git a/tests/neg-custom-args/repeatedArgs213.scala b/tests/neg-custom-args/repeatedArgs213.scala new file mode 100644 index 000000000000..ba4aeed541ca --- /dev/null +++ b/tests/neg-custom-args/repeatedArgs213.scala @@ -0,0 +1,19 @@ +import scala.collection.{immutable, mutable} +import java.nio.file.Paths + +// Start of Test +class repeatedArgs { + def bar(xs: String*): Int = xs.length + + def test(xs: immutable.Seq[String], ys: collection.Seq[String], zs: Array[String]): Unit = { + bar("a", "b", "c") + bar(xs: _*) + bar(ys: _*) // error: immutable.Seq expected, found Seq + bar(zs: _*) // old-error: Remove (compiler generated) Array to Seq convertion in 2.13? + + Paths.get("Hello", "World") + Paths.get("Hello", xs: _*) + Paths.get("Hello", ys: _*) // error: immutable.Seq expected, found Seq + Paths.get("Hello", zs: _*) + } +} diff --git a/tests/neg/repeatedArgs213.scala b/tests/neg/repeatedArgs213.scala deleted file mode 100644 index dad19f759086..000000000000 --- a/tests/neg/repeatedArgs213.scala +++ /dev/null @@ -1,43 +0,0 @@ -import scala.collection.{immutable, mutable} -import java.nio.file.Paths - -// Code below is to trick the compiler into thinking that we are -// compiling with the 2.13 standard library on the classpath. -package scala.collection { - class IterableOnce -} - -package scala.runtime { - object ScalaRunTime { - abstract class ArraySeq[+A] extends immutable.Seq[A] - - def genericWrapArray[T](xs: Array[T]): ArraySeq[T] = ??? - def wrapRefArray[T <: AnyRef](xs: Array[T]): ArraySeq[T] = ??? - def wrapIntArray(xs: Array[Int]): ArraySeq[Int] = ??? - def wrapDoubleArray(xs: Array[Double]): ArraySeq[Double] = ??? - def wrapLongArray(xs: Array[Long]): ArraySeq[Long] = ??? - def wrapFloatArray(xs: Array[Float]): ArraySeq[Float] = ??? - def wrapCharArray(xs: Array[Char]): ArraySeq[Char] = ??? - def wrapByteArray(xs: Array[Byte]): ArraySeq[Byte] = ??? - def wrapShortArray(xs: Array[Short]): ArraySeq[Short] = ??? - def wrapBooleanArray(xs: Array[Boolean]): ArraySeq[Boolean] = ??? - def wrapUnitArray(xs: Array[Unit]): ArraySeq[Unit] = ??? - } -} - -// Start of Test -class repeatedArgs { - def bar(xs: String*): Int = xs.length - - def test(xs: immutable.Seq[String], ys: collection.Seq[String], zs: Array[String]): Unit = { - bar("a", "b", "c") - bar(xs: _*) - bar(ys: _*) // error: immutable.Seq expected, found Seq - bar(zs: _*) // old-error: Remove (compiler generated) Array to Seq convertion in 2.13? - - Paths.get("Hello", "World") - Paths.get("Hello", xs: _*) - Paths.get("Hello", ys: _*) // error: immutable.Seq expected, found Seq - Paths.get("Hello", zs: _*) - } -} diff --git a/tests/pos/repeatedArgs213.scala b/tests/pos-special/repeatedArgs213.scala similarity index 85% rename from tests/pos/repeatedArgs213.scala rename to tests/pos-special/repeatedArgs213.scala index b6b52513ff69..4760dc44ef72 100644 --- a/tests/pos/repeatedArgs213.scala +++ b/tests/pos-special/repeatedArgs213.scala @@ -1,12 +1,7 @@ import scala.collection.{immutable, mutable} import java.nio.file.Paths -// Code below is to trick the compiler into thinking that we are -// compiling with the 2.13 standard library on the classpath. -package scala.collection { - class IterableOnce -} - +// Missing from 2.12 standard library package scala.runtime { object ScalaRunTime { abstract class ArraySeq[+A] extends immutable.Seq[A] @@ -27,7 +22,8 @@ package scala.runtime { // Start of Test class repeatedArgs { - def bar(xs: String*): Int = xs.length + def bar(xs: String*): Int = bat(xs) + def bat(xs: immutable.Seq[String]) = xs.length def test(xs: immutable.Seq[String]): Unit = { bar("a", "b", "c")