Skip to content

Commit

Permalink
Upgrade to Scala 2.13 (#266)
Browse files Browse the repository at this point in the history
* Upgrade to Scala 2.13
* Fix incompatibilities/deprecations which prevented compiling
* Added deprecation checks in sbt
* Fix some Scala 2.13 / Scala 3 deprecation warnings
* Fix MapView -> Map handling for Scala 2.13
GreyCat authored Feb 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 29d37b8 commit 8be2e2e
Showing 11 changed files with 18 additions and 17 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -40,7 +40,8 @@ lazy val compiler = crossProject(JSPlatform, JVMPlatform).
}
},
licenses := Seq(("GPL-3.0", url("https://opensource.org/licenses/GPL-3.0"))),
scalaVersion := "2.12.18",
scalaVersion := "2.13.13",
scalacOptions := Seq("-unchecked", "-deprecation"),

// Repo publish options
publishTo := version { (v: String) =>
8 changes: 4 additions & 4 deletions jvm/src/main/scala/io/kaitai/struct/JavaMain.scala
Original file line number Diff line number Diff line change
@@ -35,14 +35,14 @@ object JavaMain {

head(Version.name, Version.version)

arg[String]("<file>...") unbounded() action { (x, c) =>
arg[String]("<file>...").unbounded().action { (x, c) =>
c.copy(srcFiles = c.srcFiles :+ x) } text("source files (.ksy)")

// opt[File]('o', "outfile") valueName("<file>") action { (x, c) =>
// c.copy(outDir = x)
// } text("output filename (only if processing 1 file)")

opt[String]('t', "target") required() unbounded() valueName("<language>") action { (x, c) =>
opt[String]('t', "target").required().unbounded().valueName("<language>").action { (x, c) =>
// TODO: make support for something like "-t java,python"
if (x == "all") {
c.copy(targets = ALL_LANGS.toSeq)
@@ -62,7 +62,7 @@ object JavaMain {
} text("output directory (filenames will be auto-generated); on Unix-like shells, the short form `-d` requires arguments to be preceded by `--`")

val importPathExample = List("<directory>", "<directory>", "...").mkString(File.pathSeparator)
opt[String]('I', "import-path") optional() unbounded() valueName(importPathExample) action { (x, c) =>
opt[String]('I', "import-path").optional().unbounded().valueName(importPathExample).action { (x, c) =>
c.copy(importPaths = c.importPaths ++ x.split(File.pathSeparatorChar))
} text(".ksy library search path(s) for imports (see also KSPATH env variable)")

@@ -76,7 +76,7 @@ object JavaMain {
)
} text("C++ namespace (C++ only, default: none)")

opt[String]("cpp-standard") valueName("<standard>") action { (x, c) =>
opt[String]("cpp-standard").valueName("<standard>").action { (x, c) =>
c.copy(
runtime = c.runtime.copy(
cppConfig = x match {
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ object JavaKSYParser {
case jlist: JList[AnyRef] =>
jlist.asScala.toList.map(yamlJavaToScala)
case jmap: JMap[String, AnyRef] =>
jmap.asScala.toMap.mapValues(yamlJavaToScala)
jmap.asScala.toMap.view.mapValues(yamlJavaToScala).toMap
case _: String =>
src
case _: Double =>
Original file line number Diff line number Diff line change
@@ -185,7 +185,7 @@ class ExpressionsSpec extends AnyFunSpec {

it("parses [1, 2, 0x1234]") {
Expressions.parse("[1, 2, 0x1234]") should be (
List(ArrayBuffer(IntNum(1), IntNum(2), IntNum(4660)))
List(Seq(IntNum(1), IntNum(2), IntNum(4660)))
)
}

Original file line number Diff line number Diff line change
@@ -685,7 +685,7 @@ class TranslatorSpec extends AnyFunSuite {
* @param expType Expected type that should be detected by [[TypeDetector]]
* @param expOut Map with expected outputs for each language
*/
def runTest(src: String, tp: TypeProvider, expType: DataType, expOut: ResultMap) {
def runTest(src: String, tp: TypeProvider, expType: DataType, expOut: ResultMap): Unit = {
var eo: Option[Ast.expr] = None
test(s"_expr:$src") {
eo = Some(Expressions.parse(src))
4 changes: 2 additions & 2 deletions shared/src/main/scala/io/kaitai/struct/ClassCompiler.scala
Original file line number Diff line number Diff line change
@@ -367,12 +367,12 @@ class ClassCompiler(
case _ => false
}

def compileClassDoc(curClass: ClassSpec) = {
def compileClassDoc(curClass: ClassSpec): Unit = {
if (!curClass.doc.isEmpty)
lang.classDoc(curClass.name, curClass.doc)
}

def compileInstanceDoc(instName: Identifier, instSpec: InstanceSpec) {
def compileInstanceDoc(instName: Identifier, instSpec: InstanceSpec): Unit = {
if (!instSpec.doc.isEmpty)
lang.attributeDoc(instName, instSpec.doc)
}
2 changes: 1 addition & 1 deletion shared/src/main/scala/io/kaitai/struct/JSON.scala
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ object JSON extends CommonLiterals {
def seqToJson(obj: Seq[_]): String =
"[" + obj.map((x) => stringify(x)).mkString(",") + "]"

def mapToJson(obj: Map[String, _]): String = {
def mapToJson(obj: Map[String, Any]): String = {
val kvs = obj.map { case (k, v) =>
stringToJson(k) + ": " + stringify(v)
}
4 changes: 2 additions & 2 deletions shared/src/main/scala/io/kaitai/struct/Log.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.kaitai.struct

sealed trait Logger {
def info(msgGen: () => String)
def warn(msgGen: () => String)
def info(msgGen: () => String): Unit
def warn(msgGen: () => String): Unit
}

case object NullLogger extends Logger {
4 changes: 2 additions & 2 deletions shared/src/main/scala/io/kaitai/struct/format/AttrSpec.scala
Original file line number Diff line number Diff line change
@@ -183,7 +183,7 @@ object AttrSpec {
val include = ParseUtils.getOptValueBool(srcMap, "include", path).getOrElse(false)
val eosError = ParseUtils.getOptValueBool(srcMap, "eos-error", path).getOrElse(true)
val padRight = ParseUtils.getOptValueInt(srcMap, "pad-right", path)
val enum = ParseUtils.getOptValueStr(srcMap, "enum", path)
val enumOpt = ParseUtils.getOptValueStr(srcMap, "enum", path)
val parent = ParseUtils.getOptValueExpression(srcMap, "parent", path)
val valid = srcMap.get("valid").map(ValidationSpec.fromYaml(_, path ++ List("valid")))

@@ -203,7 +203,7 @@ object AttrSpec {
val yamlAttrArgs = YamlAttrArgs(
size, sizeEos,
encoding, terminator, include, consume, eosError, padRight,
contents, enum, parent, process
contents, enumOpt, parent, process
)

// Unfortunately, this monstrous match can't rewritten in simpler way due to Java type erasure
Original file line number Diff line number Diff line change
@@ -228,7 +228,7 @@ object ClassSpec {
}
}

private def checkDupId(prevAttrOpt: Option[MemberSpec], id: String, nowAttr: YAMLPath) {
private def checkDupId(prevAttrOpt: Option[MemberSpec], id: String, nowAttr: YAMLPath): Unit = {
prevAttrOpt match {
case Some(prevAttr) =>
throw KSYParseError.withText(
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ object InstanceSpec {
val pos = ParseUtils.getOptValueExpression(srcMap, "pos", path)
val io = ParseUtils.getOptValueExpression(srcMap, "io", path)

val fakeAttrMap = srcMap.filterKeys((key) => key != "pos" && key != "io")
val fakeAttrMap = srcMap.view.filterKeys((key) => key != "pos" && key != "io").toMap
val a = AttrSpec.fromYaml(fakeAttrMap, path, metaDef, id)
val valid = srcMap.get("valid").map(ValidationSpec.fromYaml(_, path ++ List("valid")))

0 comments on commit 8be2e2e

Please sign in to comment.