Skip to content

Resolve SeqType based on a compiler flag #5637

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 2 commits into from
Jan 4, 2019
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
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
}

Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 -----------------------------------------------------------------
Expand Down
19 changes: 19 additions & 0 deletions tests/neg-custom-args/repeatedArgs213.scala
Original file line number Diff line number Diff line change
@@ -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: _*)
}
}
43 changes: 0 additions & 43 deletions tests/neg/repeatedArgs213.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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")
Expand Down