Skip to content

Commit 6563295

Browse files
Harmonize scalac flags and enable Xlint/Werror (#352)
Fixes #341 and #298
1 parent 4e7f3c6 commit 6563295

39 files changed

Lines changed: 117 additions & 119 deletions

bench/src/main/scala/sjsonnet/MainBenchmark.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object MainBenchmark {
1818

1919
def findFiles(): (IndexedSeq[(Path, String)], EvalScope) = {
2020
val parser = mainargs.ParserForClass[Config]
21-
val config = parser.constructEither(MainBenchmark.mainArgs, autoPrintHelpAndExit = None).getOrElse(???)
21+
val config = parser.constructEither(MainBenchmark.mainArgs.toIndexedSeq, autoPrintHelpAndExit = None).getOrElse(???)
2222
val file = config.file
2323
val wd = os.pwd
2424
val path = OsPath(os.Path(file, wd))

bench/src/main/scala/sjsonnet/MaterializerBenchmark.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MaterializerBenchmark {
2222
@Setup
2323
def setup(): Unit = {
2424
val parser = mainargs.ParserForClass[Config]
25-
val config = parser.constructEither(MainBenchmark.mainArgs, autoPrintHelpAndExit = None).getOrElse(???)
25+
val config = parser.constructEither(MainBenchmark.mainArgs.toIndexedSeq, autoPrintHelpAndExit = None).getOrElse(???)
2626
val file = config.file
2727
val wd = os.pwd
2828
val path = os.Path(file, wd)
@@ -31,7 +31,7 @@ class MaterializerBenchmark {
3131
Map.empty[String, String],
3232
Map.empty[String, String],
3333
OsPath(wd),
34-
importer = SjsonnetMain.resolveImport(config.jpaths.map(os.Path(_, wd)).map(OsPath(_)), None),
34+
importer = SjsonnetMain.resolveImport(config.jpaths.map(os.Path(_, wd)).map(OsPath(_)).toIndexedSeq, None),
3535
parseCache = new DefaultParseCache
3636
)
3737
value = interp.evaluate(os.read(path), OsPath(path)).getOrElse(???)

bench/src/main/scala/sjsonnet/ProfilingEvaluator.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import scala.collection.compat.*
55
import scala.collection.mutable
66
import scala.jdk.CollectionConverters.*
77

8-
class ProfilingEvaluator(resolver: CachedResolver,
9-
extVars: String => Option[Expr],
10-
wd: Path,
11-
settings: Settings,
12-
warn: Error => Unit)
13-
extends Evaluator(resolver, extVars, wd, settings, warn) {
8+
class ProfilingEvaluator(r: CachedResolver,
9+
e: String => Option[Expr],
10+
w: Path,
11+
s: Settings,
12+
wa: Error => Unit)
13+
extends Evaluator(r, e, w, s, wa) {
1414

1515
trait Box {
1616
def name: String

bench/src/main/scala/sjsonnet/RunProfiler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import java.io.StringWriter
44

55
object RunProfiler extends App {
66
val parser = mainargs.ParserForClass[Config]
7-
val config = parser.constructEither(MainBenchmark.mainArgs, autoPrintHelpAndExit = None).getOrElse(???)
7+
val config = parser.constructEither(MainBenchmark.mainArgs.toIndexedSeq, autoPrintHelpAndExit = None).getOrElse(???)
88
val file = config.file
99
val wd = os.pwd
1010
val path = OsPath(os.Path(file, wd))
@@ -13,7 +13,7 @@ object RunProfiler extends App {
1313
Map.empty[String, String],
1414
Map.empty[String, String],
1515
OsPath(wd),
16-
importer = SjsonnetMain.resolveImport(config.jpaths.map(os.Path(_, wd)).map(OsPath(_)), None),
16+
importer = SjsonnetMain.resolveImport(config.jpaths.map(os.Path(_, wd)).map(OsPath(_)).toIndexedSeq, None),
1717
parseCache = parseCache
1818
) {
1919
override def createEvaluator(resolver: CachedResolver, extVars: String => Option[Expr], wd: Path,

build.sbt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@ val scala3 = "3.3.5"
55

66
cancelable in Global := true
77

8-
val scala3Options = Seq()
9-
val scala2Options = Seq("-opt:l:inline", "-opt-inline-from:sjsonnet.*,sjsonnet.**", "-Xsource:3")
8+
val commonOptions = Seq("-deprecation", "-Werror")
9+
val scala3Options = Seq("-Wconf:origin=scala.collection.compat.*:s", "-Xlint:all")
10+
val scala213Options = Seq(
11+
"-opt:l:inline",
12+
"-opt-inline-from:sjsonnet.*,sjsonnet.**",
13+
"-Xsource:3",
14+
"-Xlint:_",
15+
"-Wconf:origin=scala.collection.compat.*:s")
1016

1117
lazy val commonSettings = Seq(
1218
scalaVersion := scala3,
1319
crossScalaVersions := Seq(scala213, scala3),
14-
scalacOptions ++= {CrossVersion.partialVersion(scalaVersion.value) match {
20+
scalacOptions ++= commonOptions ++ {CrossVersion.partialVersion(scalaVersion.value) match {
1521
case Some((3, _)) => scala3Options
16-
case _ => scala2Options
22+
case _ => scala213Options
1723
}}
1824
)
1925

build.sc

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ trait SjsonnetCrossModule extends CrossScalaModule with PublishModule {
4444
Developer("lihaoyi", "Li Haoyi","https://github.com/lihaoyi")
4545
)
4646
)
47+
def scalacOptions = Seq("-deprecation", "-Werror") ++ (
48+
if (!ZincWorkerUtil.isScala3(scalaVersion())) Seq(
49+
"-opt:l:inline",
50+
"-opt-inline-from:sjsonnet.*,sjsonnet.**",
51+
"-Xsource:3",
52+
"-Xlint:_") ++ (
53+
if (scalaVersion() startsWith "2.13") Seq("-Wconf:origin=scala.collection.compat.*:s")
54+
else Seq("-Xfatal-warnings", "-Ywarn-unused:-nowarn"))
55+
else Seq[String]("-Wconf:origin=scala.collection.compat.*:s", "-Xlint:all")
56+
)
4757
trait CrossTests extends ScalaModule with TestModule.Utest {
4858
def ivyDeps = Agg(ivy"com.lihaoyi::utest::0.8.5")
4959
}
@@ -69,11 +79,6 @@ object sjsonnet extends Module {
6979
)
7080
object test extends ScalaJSTests with CrossTests {
7181
def jsEnvConfig = JsEnvConfig.NodeJs(args=List("--stack-size=" + stackSizekBytes))
72-
def sources = T.sources(
73-
this.millSourcePath / "src",
74-
this.millSourcePath / "src-js",
75-
this.millSourcePath / "src-jvm-js"
76-
)
7782
def generatedSources = T{
7883
val files = os.walk(this.millSourcePath / "resources").filterNot(os.isDir).map(p => p.relativeTo(this.millSourcePath / "resources") -> os.read.bytes(p)).toMap
7984
os.write(
@@ -133,13 +138,7 @@ object sjsonnet extends Module {
133138
def forkEnv = Map(
134139
"SCALANATIVE_THREAD_STACK_SIZE" -> stackSize,
135140
)
136-
def scalaNativeVersion = SjsonnetNativeModule.this.scalaNativeVersion
137141
def nativeLTO = LTO.None
138-
def sources = T.sources(
139-
this.millSourcePath / "src",
140-
this.millSourcePath / "src-native",
141-
this.millSourcePath / "src-jvm-native"
142-
)
143142
}
144143
}
145144

@@ -159,18 +158,9 @@ object sjsonnet extends Module {
159158
ivy"org.yaml:snakeyaml::2.0",
160159
ivy"com.google.re2j:re2j:1.8",
161160
)
162-
def scalacOptions = super.scalacOptions() ++ (
163-
if (!ZincWorkerUtil.isScala3(scalaVersion())) Seq("-opt:l:inline", "-opt-inline-from:sjsonnet.*,sjsonnet.**", "-Xsource:3")
164-
else Seq[String]()
165-
)
166161

167162
object test extends ScalaTests with CrossTests {
168163
def forkArgs = Seq("-Xss" + stackSize)
169-
def sources = T.sources(
170-
this.millSourcePath / "src",
171-
this.millSourcePath / "src-jvm",
172-
this.millSourcePath / "src-jvm-native"
173-
)
174164
}
175165

176166
object client extends JavaModule {

sjsonnet/src-js/java/util/BitSet.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package java.util
33
import java.util.stream.IntStream
44

55
import scala.collection.mutable.{BitSet => SBitSet}
6-
import scala.collection.JavaConverters._
76

87
class BitSet(_initialSizeDummy: Int) extends java.lang.Cloneable {
98
val bs: SBitSet = SBitSet.empty

sjsonnet/src-jvm-native/sjsonnet/SjsonnetMain.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object SjsonnetMain {
2222
.find(os.exists)
2323
.flatMap(p => try Some(OsPath(p)) catch{case NonFatal(_) => None})
2424

25-
def read(path: Path, binaryData: Boolean = false): Option[ResolvedFile] = {
25+
def read(path: Path, binaryData: Boolean): Option[ResolvedFile] = {
2626
readPath(path, binaryData)
2727
}
2828
}
@@ -61,7 +61,7 @@ object SjsonnetMain {
6161
val doc = "usage: sjsonnet [sjsonnet-options] script-file"
6262
val result = for{
6363
config <- parser.constructEither(
64-
args,
64+
args.toIndexedSeq,
6565
allowRepeats = true,
6666
customName = name, customDoc = doc,
6767
autoPrintHelpAndExit = None
@@ -144,9 +144,10 @@ object SjsonnetMain {
144144
codeFiles: Seq[String],
145145
wd: os.Path) = {
146146

147-
def split(s: String) = s.split("=", 2) match{
147+
def split(s: String) = s.split("=", 2) match {
148148
case Array(x) => (x, System.getenv(x))
149149
case Array(x, v) => (x, v)
150+
case _ => ???
150151
}
151152

152153
def splitMap(s: Seq[String], f: String => String) = s.map(split).map{case (x, v) => (x, f(v))}
@@ -167,10 +168,10 @@ object SjsonnetMain {
167168
config: Config,
168169
parseCache: ParseCache,
169170
wd: os.Path,
170-
allowedInputs: Option[Set[os.Path]] = None,
171-
importer: Option[(Path, String) => Option[os.Path]] = None,
172-
warnLogger: String => Unit = null,
173-
std: Val.Obj = new Std().Std): Either[String, String] = {
171+
allowedInputs: Option[Set[os.Path]],
172+
importer: Option[(Path, String) => Option[os.Path]],
173+
warnLogger: String => Unit,
174+
std: Val.Obj): Either[String, String] = {
174175

175176
val (jsonnetCode, path) =
176177
if (config.exec.value) (file, wd / Util.wrapInLessThanGreaterThan("exec"))

sjsonnet/src-native/java/util/BitSet.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package java.util
33
import java.util.stream.IntStream
44

55
import scala.collection.mutable.{BitSet => SBitSet}
6-
import scala.collection.JavaConverters._
76

87
class BitSet(_initialSizeDummy: Int) extends java.lang.Cloneable {
98
val bs: SBitSet = SBitSet.empty

sjsonnet/src/sjsonnet/DecimalFormat.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object DecimalFormat {
2222
def leftPad(n: Long, targetWidth: Int): String = {
2323
val sign = if (n < 0) "-" else ""
2424
val absN = math.abs(n)
25-
val nWidth = if (absN == 0) 1 else Math.log10(absN).toInt + 1
25+
val nWidth = if (absN == 0) 1 else Math.log10(absN.toDouble).toInt + 1
2626
sign + "0" * (targetWidth - nWidth) + absN
2727
}
2828
def rightPad(n0: Long, minWidth: Int, maxWidth: Int): String = {
@@ -39,13 +39,13 @@ object DecimalFormat {
3939
case Some(expLength) =>
4040
val roundLog10 = Math.ceil(Math.log10(Math.abs(number))).toLong
4141
val expNum = roundLog10 - 1
42-
val scaled = number / math.pow(10, expNum)
42+
val scaled = number / math.pow(10, expNum.toDouble)
4343
val prefix = scaled.toLong.toString
4444
val expFrag = leftPad(expNum, expLength)
4545
val fracFrag = fracLengthOpt.map{case (zeroes, hashes) =>
4646
if (zeroes == 0 && hashes == 0) ""
4747
else {
48-
val divided = number / Math.pow(10, expNum - zeroes - hashes)
48+
val divided = number / Math.pow(10, (expNum - zeroes - hashes).toDouble)
4949
val scaledFrac = divided % Math.pow(10, zeroes + hashes)
5050
rightPad(Math.abs(Math.round(scaledFrac)), zeroes, zeroes + hashes)
5151
}

0 commit comments

Comments
 (0)