Skip to content

Commit 6ab1ced

Browse files
bishaboshacheeseng
authored andcommitted
build with 2.13 stdlib
1 parent f2e7438 commit 6ab1ced

File tree

12 files changed

+78
-82
lines changed

12 files changed

+78
-82
lines changed

common-test.dotty/src/main/scala/org/scalatest/SharedHelpers.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import scala.collection.SortedSet
2626
import FailureMessages.decorateToStringValue
2727
import java.util.concurrent.Executors
2828
import org.scalactic.Prettifier
29+
import org.scalactic.ArrayHelper.deep
2930

3031
object SharedHelpers extends Assertions with LineNumberHelper {
3132

@@ -855,7 +856,7 @@ object SharedHelpers extends Assertions with LineNumberHelper {
855856
case map: GenMap[_, _] => element.asInstanceOf[Tuple2[_, _]]._1
856857
case genTrv: GenTraversable[_] => getIndex(xs, element)
857858
}
858-
Array(indexOrKey.toString, element.length.toString, (if (element != null && element.isInstanceOf[Array[_]]) element.asInstanceOf[Array[T]].deep.toString else element.toString))
859+
Array(indexOrKey.toString, element.length.toString, (if (element != null && element.isInstanceOf[Array[_]]) deep(element.asInstanceOf[Array[T]]).toString else element.toString))
859860
}
860861

861862
def indexLengthElement[T](itr: java.util.Iterator[String], xs: java.util.Collection[String], errorFun: String => Boolean): Array[String] = {
@@ -865,7 +866,7 @@ object SharedHelpers extends Assertions with LineNumberHelper {
865866
case map: java.util.Map[_, _] => element.asInstanceOf[java.util.Map.Entry[_, _]].getKey
866867
case genTrv: java.util.Collection[_] => getIndex(xs, element)
867868
}
868-
Array(indexOrKey.toString, element.length.toString, (if (element != null && element.isInstanceOf[Array[_]]) element.asInstanceOf[Array[T]].deep.toString else element.toString))
869+
Array(indexOrKey.toString, element.length.toString, (if (element != null && element.isInstanceOf[Array[_]]) deep(element.asInstanceOf[Array[T]]).toString else element.toString))
869870
}
870871

871872
def indexElementLengthString[T](itr: Iterator[String], xs: GenTraversable[String], errorFun: String => Boolean): Array[String] = {

project/DottyBuild.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trait DottyBuild { this: BuildCommons =>
1313

1414
// List of available night build at https://repo1.maven.org/maven2/ch/epfl/lamp/dotty-compiler_0.14/
1515
// lazy val dottyVersion = dottyLatestNightlyBuild.get
16-
lazy val dottyVersion = "0.17.0-RC1"
16+
lazy val dottyVersion = "0.18.1"
1717
lazy val dottySettings = List(
1818
scalaVersion := dottyVersion,
1919
libraryDependencies := libraryDependencies.value.map(_.withDottyCompat(scalaVersion.value)),

project/GenArrayHelper.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object GenArrayHelper {
2121

2222
def genMain(targetDir: File, version: String, scalaVersion: String): Seq[File] = {
2323
val content =
24-
if (scalaVersion startsWith "2.13")
24+
if (ScalaVersionHelper.isStdLibCompat_213(scalaVersion))
2525
"""/*
2626
| * Copyright 2001-2018 Artima, Inc.
2727
| *

project/GenColCompatHelper.scala

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object GenColCompatHelper {
2121

2222
def genMain(targetDir: File, version: String, scalaVersion: String): Seq[File] = {
2323
val content =
24-
if (scalaVersion startsWith "2.13")
24+
if (ScalaVersionHelper.isStdLibCompat_213(scalaVersion))
2525
"""/*
2626
| * Copyright 2001-2018 Artima, Inc.
2727
| *
@@ -53,7 +53,9 @@ object GenColCompatHelper {
5353
|
5454
| type Factory[-A, +C] = scala.collection.Factory[A, C]
5555
|
56-
| object Factory {}
56+
| object Factory {
57+
| $$DOTTY_CONVERSION_METHODS$$
58+
| }
5759
|
5860
| def className(col: scala.collection.Iterable[_]): String = {
5961
| val colToString = col.toString
@@ -69,7 +71,10 @@ object GenColCompatHelper {
6971
| type StringOps = scala.collection.StringOps
7072
|}
7173
|
72-
""".stripMargin
74+
""".replaceAllLiterally(
75+
"$$DOTTY_CONVERSION_METHODS$$",
76+
if (ScalaVersionHelper.isDotty(scalaVersion)) dottyColCompatHelperFactoryMethods else "")
77+
.stripMargin
7378
else
7479
"""/*
7580
| * Copyright 2001-2018 Artima, Inc.
@@ -137,9 +142,23 @@ object GenColCompatHelper {
137142
)
138143
}
139144

145+
private def dottyColCompatHelperFactoryMethods: String = """
146+
| implicit def mkFactoryFromList[A]: Conversion[scala.collection.immutable.List.type, scala.collection.Factory[A, scala.collection.immutable.List[A]]] =
147+
| scala.collection.IterableFactory.toFactory(_)
148+
|
149+
| implicit def mkFactoryFromVector[A]: Conversion[scala.collection.immutable.Vector.type, scala.collection.Factory[A, scala.collection.immutable.Vector[A]]] =
150+
| scala.collection.IterableFactory.toFactory(_)
151+
|
152+
| implicit def mkFactoryFromSet[A]: Conversion[scala.collection.immutable.Set.type, scala.collection.Factory[A, scala.collection.immutable.Set[A]]] =
153+
| scala.collection.IterableFactory.toFactory(_)
154+
|
155+
| implicit def mkFactoryFromListBuffer[A]: Conversion[scala.collection.mutable.ListBuffer.type, scala.collection.Factory[A, scala.collection.mutable.ListBuffer[A]]] =
156+
| scala.collection.IterableFactory.toFactory(_)
157+
""".stripMargin
158+
140159
def genTest(targetDir: File, version: String, scalaVersion: String): Seq[File] = {
141160
val chainSpec =
142-
if (scalaVersion startsWith "2.13")
161+
if (ScalaVersionHelper.isStdLibCompat_213(scalaVersion))
143162
"""/*
144163
| * Copyright 2001-2018 Artima, Inc.
145164
| *
@@ -213,7 +232,7 @@ object GenColCompatHelper {
213232
""".stripMargin
214233

215234
val everySpec =
216-
if (scalaVersion startsWith "2.13")
235+
if (ScalaVersionHelper.isStdLibCompat_213(scalaVersion))
217236
"""/*
218237
| * Copyright 2001-2018 Artima, Inc.
219238
| *

project/GenCompatibleClasses.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ object GenCompatibleClasses {
8080
targetDir.mkdirs()
8181
val file = new File(targetDir, "CompatParColls.scala")
8282
if (!file.exists || generatorSource.lastModified > file.lastModified) {
83-
val parMethod = if (scalaVersion startsWith "2.13") "def par: T = oriCol" else ""
83+
val parMethod = if(ScalaVersionHelper.isStdLibCompat_213(scalaVersion)) "def par: T = oriCol" else ""
8484
/*
8585
For recording purpose, this is the original version of CompatParColls that stops working in 2.13.0-M4
8686
/**

project/GenConfigMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object GenConfigMap {
2121

2222
def genMain(targetDir: File, version: String, scalaVersion: String): Seq[File] = {
2323
val content =
24-
if (scalaVersion startsWith "2.13")
24+
if(ScalaVersionHelper.isStdLibCompat_213(scalaVersion))
2525
"""/*
2626
| * Copyright 2001-2013 Artima, Inc.
2727
| *

project/GenEvery.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import scala.io.Source
66
object GenEvery {
77

88
def transformLine(line: String, scalaVersion: String): String = {
9-
if (scalaVersion startsWith "2.13")
9+
if(ScalaVersionHelper.isStdLibCompat_213(scalaVersion))
1010
line
1111
.replaceAllLiterally(": Map[K, Every[T]]", ": scala.collection.MapView[K, org.scalactic.Every[T]]")
1212
.replaceAllLiterally("final def to[Col[_]](implicit cbf: CanBuildFrom[Nothing, T, Col[T @uV]]): Col[T @uV] = underlying.to[Col](cbf)",

project/GenScalacticDotty.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ object GenScalacticDotty {
3030
else
3131
line
3232

33+
private def rewrite213(line: String): String =
34+
line.replaceAllLiterally("final def startsWith(that: GenSeq[Char]): Boolean = theString.startsWith(that)", "final def startsWith(that: GenSeq[Char]): Boolean = theString.startsWith(that.mkString)")
35+
.replaceAllLiterally("final def startsWith(that: Every[Char]): Boolean = theString.startsWith(that.toVector)", "final def startsWith(that: Every[Char]): Boolean = theString.startsWith(that.mkString)")
36+
.replaceAllLiterally("""val fn: Int => Char = NonEmptyString("123").compose((idx: Int) => (idx + 1).toChar)""", """val fn: Int => Char = NonEmptyString("123").compose { case idx => (idx + 1).toChar }""")
37+
3338
private def transformLine(line: String): String =
34-
uncommentJsExport(line)
39+
((uncommentJsExport _) andThen (rewrite213 _))(line)
3540

3641
private def copyFile(sourceFile: File, destFile: File): File = {
3742
val destWriter = new BufferedWriter(new FileWriter(destFile))

project/GenTable.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ object TableFor$n$ {
353353
"""
354354

355355
def tableTemplate(scalaVersion: String): String =
356-
if (scalaVersion startsWith "2.13")
356+
if(ScalaVersionHelper.isStdLibCompat_213(scalaVersion))
357357
tableTemplateRaw.replaceAllLiterally("scala.collection.IndexedSeqLike[($alphaUpper$), TableFor$n$[$alphaUpper$]]", "scala.collection.IndexedSeqOps[($alphaUpper$), scala.collection.IndexedSeq, scala.collection.IndexedSeq[($alphaUpper$)]]")
358358
.replaceAllLiterally("$$CLASS_BUILDER_METHODS$$", "")
359359
.replaceAllLiterally("$$OBJECT_BUILDER_METHODS$$",

project/ScalaVersionHelper.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object ScalaVersionHelper {
2+
def isStdLibCompat_213(scalaVersion: String): Boolean = {
3+
scalaVersion.startsWith("2.13") ||
4+
isDotty(scalaVersion)
5+
}
6+
7+
def isDotty(scalaVersion: String): Boolean = {
8+
scalaVersion.startsWith("3.") ||
9+
scalaVersion.matches("""0\.(?:1[8-]|2).*""")
10+
}
11+
}

0 commit comments

Comments
 (0)