Skip to content

Commit d0b063a

Browse files
committed
Add version-specific source directories in the library
And replace Tuple.scala with a Scala 2 implementation and a Scala 3 implementation. The Scala 2 implementaion of Tuple.scala is not strictly necessary but could be useful if non-version-specific library sources end up referencing scala.Tuple.
1 parent d43a22f commit d0b063a

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,11 @@ class CompilationTests extends ParallelTesting {
206206
Array("-Ycheck-reentrant", "-Yemit-tasty-in-class")
207207
)
208208

209+
val libraryDirs = List(Paths.get("library/src"), Paths.get("library/src-scala3"))
210+
val librarySources = libraryDirs.flatMap(d => sources(Files.walk(d)))
211+
209212
val lib =
210-
compileDir("library/src",
213+
compileList("src", librarySources,
211214
defaultOptions.and("-Ycheck-reentrant", "-strict", "-priorityclasspath", defaultOutputDir))(libGroup)
212215

213216
val compilerDir = Paths.get("compiler/src")

library/src/scala/Tuple.scala renamed to library/src-scala2/scala/Tuple.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ sealed trait Tuple extends Any
55

66
@showAsInfix
77
sealed class *:[+H, +T <: Tuple] extends Tuple {
8-
@`rewrite` def head: H = ???
9-
@`rewrite` def tail: T = ???
8+
def head: H = ???
9+
def tail: T = ???
1010
}
1111

1212
object *: {
13-
@`rewrite` def unapply[H, T <: Tuple](x: H *: T) = Some((x.head, x.tail))
13+
def unapply[H, T <: Tuple](x: H *: T) = Some((x.head, x.tail))
1414
}

library/src-scala3/scala/Tuple.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package scala
2+
import annotation.showAsInfix
3+
4+
object typelevel {
5+
erased def erasedValue[T]: T = ???
6+
}
7+
8+
import typelevel._
9+
10+
sealed trait Tuple extends Any
11+
12+
@showAsInfix
13+
sealed class *:[+H, +T <: Tuple] extends Tuple {
14+
rewrite def head: H = ???
15+
rewrite def tail: T = ???
16+
17+
rewrite private def _size(xs: Tuple): Int = //rewrite
18+
xs match {
19+
case _: Unit => 0
20+
case _: *:[_, xs1] => _size(erasedValue[xs1]) + 1
21+
}
22+
}
23+
24+
object *: {
25+
rewrite def unapply[H, T <: Tuple](x: H *: T) = Some((x.head, x.tail))
26+
}

project/Build.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,17 @@ object Build {
740740

741741
// Settings shared between dotty-library and dotty-library-bootstrapped
742742
lazy val dottyLibrarySettings = Seq(
743-
libraryDependencies += "org.scala-lang" % "scala-library" % scalacVersion
743+
libraryDependencies += "org.scala-lang" % "scala-library" % scalacVersion,
744+
// Add version-specific source directories:
745+
// - files in src-scala3 will only be compiled by dotty
746+
// - files in src-scala2 will only be compiled by scalac
747+
unmanagedSourceDirectories in Compile += {
748+
val baseDir = baseDirectory.value
749+
if (isDotty.value)
750+
baseDir / "src-scala3"
751+
else
752+
baseDir / "src-scala2"
753+
}
744754
)
745755

746756
lazy val `dotty-library` = project.in(file("library")).asDottyLibrary(NonBootstrapped)

0 commit comments

Comments
 (0)