Skip to content

Commit 4bd1647

Browse files
committed
Add Scala 2.13 import to generated files to match current source
1 parent 54d3d81 commit 4bd1647

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

library/src/scala/Function0.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
// GENERATED CODE: DO NOT EDIT.
14-
// genprod generated these sources at: 2022-01-17T20:47:12.170348200Z
14+
// genprod generated these sources at: 2025-08-11T12:52:13.642685846Z
1515

1616
package scala
1717

project/GenerateAnyVals.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package scala.build
1+
package dotty.tools
22

33
/** Code generation of the AnyVal types and their companions. */
44
trait GenerateAnyValReps {
@@ -295,6 +295,8 @@ trait GenerateAnyValTemplates {
295295
296296
package scala
297297
298+
import scala.language.`2.13`
299+
298300
"""
299301

300302
def classDocTemplate = ("""
@@ -465,7 +467,7 @@ override def getClass(): Class[Boolean] = ???
465467
* runtime system. A method with return type `Unit` is analogous to a Java
466468
* method which is declared `void`.
467469
*/
468-
"""
470+
""".trim + "\n"
469471
def classLines = List(
470472
"// Provide a more specific return type for Scaladoc",
471473
"override def getClass(): Class[Unit] = ???"

project/GenerateFunctionConverters.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package dotty.tools
2+
13
/*
24
* Scala (https://www.scala-lang.org)
35
*
@@ -338,13 +340,16 @@ object GenerateFunctionConverters {
338340
sams.toSeq.map(generate)
339341
}
340342

341-
def sourceFile(subPack: String, body: String): String =
343+
def sourceFile(subPack: String, body: String): String = {
344+
val body1 = if (body.startsWith("import "))body else "\n" + body
342345
s"""$copyright
343346
|
344347
|$packaging$subPack
345348
|
346-
|$body
349+
|import scala.language.`2.13`
350+
|$body1
347351
|""".stripMargin
352+
}
348353

349354
def sameText(f: java.io.File, text: String): Boolean = {
350355
val x = scala.io.Source.fromFile(f)

project/genprod.scala renamed to project/GenerateLibraryNTemplates.scala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package dotty.tools
2+
13
/*
24
* Scala (https://www.scala-lang.org)
35
*
@@ -14,7 +16,7 @@
1416
* This program generates the ProductN, TupleN, FunctionN, and AbstractFunctionN,
1517
* where 0 <= N <= MaxArity. Usage: sbt generateSources
1618
*/
17-
object genprod {
19+
object GenerateLibraryNTemplates {
1820
final val MaxArity = 22
1921
def arities = (1 to MaxArity).toList
2022

@@ -74,8 +76,10 @@ object genprod {
7476
// GENERATED CODE: DO NOT EDIT.%s
7577
7678
package %s
79+
80+
import scala.language.`2.13`
7781
%s
78-
""".trim.format(genprodString, packageDef, imports)
82+
""".format(genprodString, packageDef, imports).trim
7983
}
8084

8185
def run(outDir: java.io.File): Unit = {
@@ -90,7 +94,7 @@ package %s
9094
}
9195
}
9296

93-
import genprod._
97+
import GenerateLibraryNTemplates._
9498

9599

96100
/* zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
@@ -131,15 +135,15 @@ object FunctionOne extends Function(1) {
131135
* is that the latter can specify inputs which it will not handle."""
132136

133137
override def moreMethods = """
134-
/** Composes two instances of Function1 in a new Function1, with this function applied last.
138+
/** Composes two instances of `Function1` in a new `Function1`, with this function applied last.
135139
*
136140
* @tparam A the type to which function `g` can be applied
137141
* @param g a function A => T1
138142
* @return a new function `f` such that `f(x) == apply(g(x))`
139143
*/
140144
@annotation.unspecialized def compose[A](g: A => T1): A => R = { x => apply(g(x)) }
141145
142-
/** Composes two instances of Function1 in a new Function1, with this function applied first.
146+
/** Composes two instances of `Function1` in a new `Function1`, with this function applied first.
143147
*
144148
* @tparam A the result type of function `g`
145149
* @param g a function R => A
@@ -413,6 +417,7 @@ class Product(val i: Int) extends Group("Product") with Arity {
413417

414418
def apply() = {
415419
<file name={fileName}>{header}
420+
416421
object {className} {{
417422
def unapply{invariantArgs}(x: {className}{invariantArgs}): Option[{className}{invariantArgs}] =
418423
Some(x)
@@ -461,6 +466,7 @@ class AbstractFunction(val i: Int) extends Group("AbstractFunction") with Arity
461466

462467
def apply() = {
463468
<file name={"runtime/" + fileName}>{header}
469+
464470
abstract class {className}{contraCoArgs} extends Function{i}{superTypeArgs} {{
465471
{moreMethods}
466472
}}
@@ -477,3 +483,4 @@ object AbstractFunction
477483
case _ => new AbstractFunction(i)
478484
}
479485
}
486+

project/ScalaLibraryPlugin.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,19 @@ object ScalaLibraryPlugin extends AutoPlugin {
8181
previous
8282
.withAnalysis(analysis.copy(stamps = stamps)) // update the analysis with the correct stamps
8383
.withHasModified(true) // mark it as updated for sbt to update its caches
84-
}
84+
},
85+
86+
// Generate (Product|TupleN|Function|AbstractFunction)*.scala files and scaladoc stubs for all AnyVal sources.
87+
// They should really go into a managedSources dir instead of overwriting sources checked into git but scaladoc
88+
// source links (could be fixed by shipping these sources with the scaladoc bundles) and scala-js source maps
89+
// rely on them being on github.
90+
commands += Command.command("generateSources") { state =>
91+
val dir = ((ThisBuild / baseDirectory).value / "library" / "src" / "scala").getAbsoluteFile
92+
dotty.tools.GenerateLibraryNTemplates.run(dir)
93+
dotty.tools.GenerateAnyVals.run(dir)
94+
dotty.tools.GenerateFunctionConverters.run(dir)
95+
state
96+
},
8597
)
8698

8799
private lazy val filesToCopy = Set(

0 commit comments

Comments
 (0)