@@ -490,6 +490,24 @@ object Build {
490
490
def findArtifactPath (classpath : Def .Classpath , name : String ): String =
491
491
findArtifact(classpath, name).getAbsolutePath
492
492
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
+
493
511
// Settings shared between scala3-compiler and scala3-compiler-bootstrapped
494
512
lazy val commonDottyCompilerSettings = Seq (
495
513
// Generate compiler.properties, used by sbt
@@ -706,7 +724,12 @@ object Build {
706
724
IO .createDirectory(trgDir)
707
725
IO .unzip(scalaJSIRSourcesJar, trgDir)
708
726
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
710
733
} (Set (scalaJSIRSourcesJar)).toSeq
711
734
}.taskValue,
712
735
)
@@ -761,7 +784,7 @@ object Build {
761
784
)
762
785
},
763
786
764
- Compile / scalacOptions ++= Seq (" -Yexplicit-nulls" , " -language:unsafeNulls" ),
787
+ Compile / scalacOptions ++= Seq (" -Yexplicit-nulls" ), // "-language:unsafeNulls"),
765
788
766
789
repl := (Compile / console).value,
767
790
Compile / console / scalacOptions := Nil , // reset so that we get stock REPL behaviour! E.g. avoid -unchecked being enabled
0 commit comments