Skip to content

Commit a112511

Browse files
committed
Add unsafeNulls imports to scalajs source
1 parent e5e7a68 commit a112511

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

project/Build.scala

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,24 @@ object Build {
490490
def findArtifactPath(classpath: Def.Classpath, name: String): String =
491491
findArtifact(classpath, name).getAbsolutePath
492492

493+
/** Insert UnsafeNulls Import after package */
494+
def insertUnsafeNullsImport(lines: Seq[String]): Seq[String] = {
495+
// var foundPackage = false
496+
def recur(ls: Seq[String], foundPackage: Boolean): Seq[String] = ls match {
497+
case Seq(l, rest @ _*) =>
498+
val lt = l.trim()
499+
if (foundPackage) {
500+
if (!(lt.isEmpty || lt.startsWith("package ")))
501+
"import scala.language.unsafeNulls" +: ls
502+
else l +: recur(rest, foundPackage)
503+
} else {
504+
if (lt.startsWith("package ")) l +: recur(rest, true)
505+
else l +: recur(rest, foundPackage)
506+
}
507+
}
508+
recur(lines, false)
509+
}
510+
493511
// Settings shared between scala3-compiler and scala3-compiler-bootstrapped
494512
lazy val commonDottyCompilerSettings = Seq(
495513
// Generate compiler.properties, used by sbt
@@ -706,7 +724,12 @@ object Build {
706724
IO.createDirectory(trgDir)
707725
IO.unzip(scalaJSIRSourcesJar, trgDir)
708726

709-
(trgDir ** "*.scala").get.toSet
727+
val sjsSources = (trgDir ** "*.scala").get.toSet
728+
sjsSources.foreach(f => {
729+
val lines = IO.readLines(f)
730+
IO.writeLines(f, insertUnsafeNullsImport(lines))
731+
})
732+
sjsSources
710733
} (Set(scalaJSIRSourcesJar)).toSeq
711734
}.taskValue,
712735
)
@@ -761,7 +784,7 @@ object Build {
761784
)
762785
},
763786

764-
Compile / scalacOptions ++= Seq("-Yexplicit-nulls", "-language:unsafeNulls"),
787+
Compile / scalacOptions ++= Seq("-Yexplicit-nulls"), //"-language:unsafeNulls"),
765788

766789
repl := (Compile / console).value,
767790
Compile / console / scalacOptions := Nil, // reset so that we get stock REPL behaviour! E.g. avoid -unchecked being enabled

0 commit comments

Comments
 (0)