Skip to content

Commit

Permalink
Resolve 2.13 cross-compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurelineSwissBorg committed Oct 22, 2024
1 parent a9005b3 commit d99d7e8
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 74 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/pr-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ jobs:
distribution: 'adopt'
- name: Run mill tests
run: ./mill __.test
- name: Compile with sbt
- name: Compile Scala 2.13 with sbt
run: sbt ++2.13 compile bench/compile bench/jmh:compile
- name: Compile Scala 2.13 with sbt
run: sbt compile bench/compile bench/jmh:compile
- name: Run sbt tests
- name: Run sbt tests (Scala 2.13)
run: sbt ++2.13 test
- name: Run sbt tests (Scala 3)
run: sbt test
19 changes: 14 additions & 5 deletions sjsonnet/src/sjsonnet/BaseCharRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ class BaseCharRenderer[T <: upickle.core.CharOps.Output]
renderIndent()
}
}
def visitArray(length: Int, index: Int) = new ArrVisitor[T, T] {

def visitArray(length: Int, index: Int): ArrVisitor[T, T] = new ArrVisitor[T, T] {
flushBuffer()
elemBuilder.append('[')

depth += 1
renderIndent()
def subVisitor = BaseCharRenderer.this

def subVisitor: BaseCharRenderer[T] = BaseCharRenderer.this

def visitValue(v: T, index: Int): Unit = {
flushBuffer()
commaBuffered = true
}

def visitEnd(index: Int) = {
commaBuffered = false
depth -= 1
Expand All @@ -49,20 +53,25 @@ class BaseCharRenderer[T <: upickle.core.CharOps.Output]
}
}

def visitJsonableObject(length: Int, index: Int) = new ObjVisitor[T, T] {
def visitJsonableObject(length: Int, index: Int): ObjVisitor[T, T] = new ObjVisitor[T, T] {
flushBuffer()
elemBuilder.append('{')
depth += 1
renderIndent()
def subVisitor = BaseCharRenderer.this
def visitKey(index: Int) = BaseCharRenderer.this

def subVisitor: BaseCharRenderer[T] = BaseCharRenderer.this

def visitKey(index: Int): BaseCharRenderer[T] = BaseCharRenderer.this

def visitKeyValue(s: Any): Unit = {
elemBuilder.append(':')
if (indent != -1) elemBuilder.append(' ')
}

def visitValue(v: T, index: Int): Unit = {
commaBuffered = true
}

def visitEnd(index: Int) = {
commaBuffered = false
depth -= 1
Expand Down
19 changes: 14 additions & 5 deletions sjsonnet/src/sjsonnet/BaseRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,21 @@ class BaseRenderer[T <: java.io.Writer]
renderIndent()
}
}
def visitArray(length: Int, index: Int) = new ArrVisitor[T, T] {

def visitArray(length: Int, index: Int): ArrVisitor[T, T] = new ArrVisitor[T, T] {
flushBuffer()
out.append('[')

depth += 1
renderIndent()
def subVisitor = BaseRenderer.this

def subVisitor: BaseRenderer[T] = BaseRenderer.this

def visitValue(v: T, index: Int): Unit = {
flushBuffer()
commaBuffered = true
}

def visitEnd(index: Int) = {
commaBuffered = false
depth -= 1
Expand All @@ -47,17 +51,22 @@ class BaseRenderer[T <: java.io.Writer]
}
}

def visitJsonableObject(length: Int, index: Int) = new ObjVisitor[T, T] {
def visitJsonableObject(length: Int, index: Int): ObjVisitor[T, T] = new ObjVisitor[T, T] {
flushBuffer()
out.append('{')
depth += 1
renderIndent()
def subVisitor = BaseRenderer.this
def visitKey(index: Int) = BaseRenderer.this

def subVisitor: BaseRenderer[T] = BaseRenderer.this

def visitKey(index: Int): BaseRenderer[T] = BaseRenderer.this

def visitKeyValue(s: Any): Unit = out.append(colonSnippet)

def visitValue(v: T, index: Int): Unit = {
commaBuffered = true
}

def visitEnd(index: Int) = {
commaBuffered = false
depth -= 1
Expand Down
4 changes: 2 additions & 2 deletions sjsonnet/src/sjsonnet/Error.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ class ParseError(msg: String, stack: List[Error.Frame] = Nil, underlying: Option
extends Error(msg, stack, underlying) {

override protected def copy(msg: String = msg, stack: List[Error.Frame] = stack,
underlying: Option[Throwable] = underlying) =
underlying: Option[Throwable] = underlying): ParseError =
new ParseError(msg, stack, underlying)
}

class StaticError(msg: String, stack: List[Error.Frame] = Nil, underlying: Option[Throwable] = None)
extends Error(msg, stack, underlying) {

override protected def copy(msg: String = msg, stack: List[Error.Frame] = stack,
underlying: Option[Throwable] = underlying) =
underlying: Option[Throwable] = underlying): StaticError =
new StaticError(msg, stack, underlying)
}

Expand Down
8 changes: 4 additions & 4 deletions sjsonnet/src/sjsonnet/Evaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -502,18 +502,18 @@ class Evaluator(resolver: CachedResolver,
def visitMemberList(objPos: Position, e: ObjBody.MemberList, sup: Val.Obj)(implicit scope: ValScope): Val.Obj = {
val asserts = e.asserts
val fields = e.fields
var cachedSimpleScope: ValScope | Null = null
var cachedSimpleScope: Option[ValScope] = None
var cachedObj: Val.Obj = null
var asserting: Boolean = false

def makeNewScope(self: Val.Obj, sup: Val.Obj): ValScope = {
if((sup eq null) && (self eq cachedObj)) {
cachedSimpleScope match {
case null =>
case None =>
val cachedScope = createNewScope(self, sup)
cachedSimpleScope = cachedScope
cachedSimpleScope = Some(cachedScope)
cachedScope
case cachedScope: ValScope =>
case Some(cachedScope) =>
cachedScope
}
} else createNewScope(self, sup)
Expand Down
6 changes: 3 additions & 3 deletions sjsonnet/src/sjsonnet/Format.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object Format{


def plain[A: P] = P( CharsWhile(_ != '%', 0).! )
def format[A: P] = P( plain ~ (("%" ~/ formatSpec) ~ plain).rep ~ End)
def format0[A: P] = P( plain ~ (("%" ~/ formatSpec) ~ plain).rep ~ End)



Expand Down Expand Up @@ -81,7 +81,7 @@ object Format{
values0: Val,
pos: Position)
(implicit evaluator: EvalScope): String = {
val (leading, chunks) = fastparse.parse(s, format).get.value
val (leading, chunks) = fastparse.parse(s, format0(using _)).get.value
format(leading, chunks, values0, pos)
}

Expand Down Expand Up @@ -257,7 +257,7 @@ object Format{
}

class PartialApplyFmt(fmt: String) extends Val.Builtin1("values") {
val (leading, chunks) = fastparse.parse(fmt, format).get.value
val (leading, chunks) = fastparse.parse(fmt, format0(using _)).get.value
def evalRhs(values0: Val, ev: EvalScope, pos: Position): Val =
Val.Str(pos, format(leading, chunks, values0, pos)(ev))
}
Expand Down
30 changes: 20 additions & 10 deletions sjsonnet/src/sjsonnet/PrettyYamlRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,20 @@ class PrettyYamlRenderer(out: Writer = new java.io.StringWriter(),
newlineBuffered = false
dashBuffered = false
}
override def visitArray(length: Int, index: Int) = new ArrVisitor[Writer, Writer] {

override def visitArray(length: Int, index: Int): ArrVisitor[Writer, Writer] = new ArrVisitor[Writer, Writer] {
var empty = true
val dedentInObject = afterKey && !indentArrayInObject
def subVisitor = {
if (empty){

def subVisitor: PrettyYamlRenderer = {
if (empty) {
afterColon = false
flushBuffer()
val outerFirstElementInArray = firstElementInArray
firstElementInArray = true
if (!topLevel) {
depth += 1
if (!firstElementInArray || !outerFirstElementInArray) newlineBuffered = true
if (!firstElementInArray || !outerFirstElementInArray) newlineBuffered = true
}
topLevel = false

Expand All @@ -161,6 +163,7 @@ class PrettyYamlRenderer(out: Writer = new java.io.StringWriter(),
leftHandPrefixOffset = 0
PrettyYamlRenderer.this
}

def visitValue(v: Writer, index: Int): Unit = {
firstElementInArray = true
empty = false
Expand All @@ -169,6 +172,7 @@ class PrettyYamlRenderer(out: Writer = new java.io.StringWriter(),

dashBuffered = true
}

def visitEnd(index: Int) = {
firstElementInArray = false
if (!dedentInObject) depth -= 1
Expand All @@ -182,16 +186,19 @@ class PrettyYamlRenderer(out: Writer = new java.io.StringWriter(),
out
}
}
override def visitJsonableObject(length: Int, index: Int) = new ObjVisitor[Writer, Writer] {

override def visitJsonableObject(length: Int, index: Int): ObjVisitor[Writer, Writer] = new ObjVisitor[Writer, Writer] {
firstElementInArray = false
var empty = true
flushBuffer()
if (!topLevel) depth += 1
topLevel = false
def subVisitor = PrettyYamlRenderer.this
def visitKey(index: Int) = {

if (empty){
def subVisitor: PrettyYamlRenderer = PrettyYamlRenderer.this

def visitKey(index: Int): PrettyYamlRenderer = {

if (empty) {
leftHandPrefixOffset = 0

afterColon = false
Expand All @@ -200,23 +207,26 @@ class PrettyYamlRenderer(out: Writer = new java.io.StringWriter(),
}
PrettyYamlRenderer.this
}

def visitKeyValue(s: Any): Unit = {
empty = false
flushBuffer()
out.append(":")
saveCurrentPos()
if (bufferedComment != null){
if (bufferedComment != null) {
out.append(bufferedComment)
bufferedComment = null
}
afterKey = true
afterColon = true
newlineBuffered = false
}

def visitValue(v: Writer, index: Int): Unit = {
newlineBuffered = true
afterKey = false
}

def visitEnd(index: Int) = {
if (empty) {
addSpaceAfterColon()
Expand Down Expand Up @@ -473,7 +483,7 @@ object PrettyYamlRenderer{
yamlPunctuation | (&(CharIn(".0-9\\-")) ~ (yamlTime | yamlDate | yamlNumber) | yamlKeyword) ~ End
)

fastparse.parse(str, parser).isSuccess ||
fastparse.parse(str, parser(using _)).isSuccess ||
str.contains(": ") || // Looks like a key-value pair
str.contains(" #") || // Comments
str.charAt(str.length - 1) == ':' || // Looks like a key-value pair
Expand Down
16 changes: 8 additions & 8 deletions sjsonnet/src/sjsonnet/ReadWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@ sealed abstract class ReadWriter[T] {
object ReadWriter{
implicit object StringRead extends ReadWriter[String]{
def apply(t: Val) = t.asString
def write(pos: Position, t: String) = Val.Str(pos, t)
def write(pos: Position, t: String): Val.Str = Val.Str(pos, t)
}
implicit object BooleanRead extends ReadWriter[Boolean]{
def apply(t: Val) = t.asBoolean
def write(pos: Position, t: Boolean) = Val.bool(pos, t)
def write(pos: Position, t: Boolean): Val.Bool = Val.bool(pos, t)
}
implicit object IntRead extends ReadWriter[Int]{
def apply(t: Val) = t.asInt
def write(pos: Position, t: Int) = Val.Num(pos, t)
def write(pos: Position, t: Int): Val.Num = Val.Num(pos, t)
}
implicit object DoubleRead extends ReadWriter[Double]{
def apply(t: Val) = t.asDouble
def write(pos: Position, t: Double) = Val.Num(pos, t)
def write(pos: Position, t: Double): Val.Num = Val.Num(pos, t)
}
implicit object ValRead extends ReadWriter[Val]{
def apply(t: Val) = t
def write(pos: Position, t: Val) = t
def write(pos: Position, t: Val): Val = t
}
implicit object ObjRead extends ReadWriter[Val.Obj]{
def apply(t: Val) = t.asObj
def write(pos: Position, t: Val.Obj) = t
def write(pos: Position, t: Val.Obj): Val.Obj = t
}
implicit object ArrRead extends ReadWriter[Val.Arr]{
def apply(t: Val) = t.asArr
def write(pos: Position, t: Val.Arr) = t
def write(pos: Position, t: Val.Arr): Val.Arr = t
}
implicit object FuncRead extends ReadWriter[Val.Func]{
def apply(t: Val) = t.asFunc
def write(pos: Position, t: Val.Func) = t
def write(pos: Position, t: Val.Func): Val.Func = t
}
}
Loading

0 comments on commit d99d7e8

Please sign in to comment.