Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions project.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@

//> using options -deprecation -feature -new-syntax -unchecked
//> using options -language:noAutoTupling
//> using options -Yexplicit-nulls
// //> using options -Wsafe-init -Werror -Wunused:all
//> using options -Vprofile -Xprint-inline
//> using options -Ycheck:macros -Ydebug-flags -Ydebug-missing-refs
//> using options -Ycheck:all
//> using options -Yexplain-lowlevel -Yexplicit-nulls
//> using options -Yshow-suppressed-errors -Yshow-var-bounds
//> using options -Wsafe-init -Werror -Wunused:all
////> using options -Yprofile-enabled" -Yprofile-trace:debug/compile-trace.json"

//> using publish.organization com.halotukozak
//> using publish.name mcodec
Expand Down
7 changes: 5 additions & 2 deletions src/mcodec/CborInput.scala
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,17 @@ class CborInput(reader: CborReader) extends InputAndSimpleInput:
case _ => ()
case _ => throw ReadFailure(s"cannot skip major type $major")

private def skipChunks(major: Int): Unit =
// TODO: `major` is accepted but never checked against each chunk's own major type
// (discarded below as `_`) — malformed CBOR with mismatched chunk major types
// inside an indefinite-length container is currently accepted rather than rejected.
private def skipChunks(@scala.annotation.unused major: Int): Unit =
var done = false
while !done do
if reader.peekU8() == 0xff then
reader.u8()
done = true
else
val (cm, ca) = reader.readInitial()
val (_, ca) = reader.readInitial()
reader.readBytes(reader.readArg(ca).toInt)

// Skip an indefinite container's items until the 0xFF break. `perItem` is the
Expand Down
7 changes: 7 additions & 0 deletions src/mcodec/Derivation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ package halotukozak.mcodec
import halotukozak.made.*
import halotukozak.made.annotation.optionalParam
import halotukozak.commons.*
import scala.annotation.nowarn

trait Derivation:
this: MCodec.type =>
transparent inline def derivedRec[T: Made.Of as m]: MCodec[T] =
val deferred = new Deferred[T]
// `self` isn't referenced by name here, but it's what lets a recursive/self-referential
// T resolve MCodec[T] via implicit search during its own derivation below (deferred ties
// the knot). -Wunused can't see that usage since it only appears after this transparent
// inline def is expanded at call sites, so it's suppressed rather than removed.
@nowarn("msg=unused local definition")
given self: MCodec[T] = deferred
val built = deriveDispatch[T](m)
deferred.underlying = built
Expand Down Expand Up @@ -118,6 +124,7 @@ trait Derivation:
val c = compiletime.summonFrom:
case given MCodec[`head`] => compiletime.summonInline[MCodec[head]]
case _ => MCodec.derived[head]
: @nowarn("msg=unused pattern variable")

c.asInstanceOf[MCodec[Any]] :: summonOrDeriveCases[tail]

Expand Down
3 changes: 1 addition & 2 deletions test/mcodec/ExtendedStdCodecsTest.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package halotukozak.mcodec

import halotukozak.mcodec.MValue.*
import org.scalacheck.{Arbitrary, Gen}
import org.scalacheck.Arbitrary

import java.lang as jl
import java.util as ju
import scala.jdk.CollectionConverters.*

class ExtendedStdCodecsTest extends RoundTrip(InMemoryBackend), JsonConv:

Expand Down
6 changes: 3 additions & 3 deletions test/mcodec/IoContractExtTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class IoContractExtTest extends munit.FunSuite:
intercept[ReadFailure](imRead(MString(""))(_.readChar()))

// ===== Float precision =====
private val floatCases =
private lazy val floatCases =
Seq(Float.MinValue, Float.MaxValue, Float.MinPositiveValue, -0.0f, 0.0f, 1.1f, 1.4e-45f, 3.14159f)

test("Float round-trips EXACTLY via InMemory"):
Expand All @@ -93,7 +93,7 @@ class IoContractExtTest extends munit.FunSuite:
assert(jsonHarvest(_.writeFloat(Float.NaN)).startsWith("\""))

// ===== Timestamp =====
private val tsCases = Seq(0L, 1L, 1L << 50, Long.MaxValue, -1000L)
private lazy val tsCases = Seq(0L, 1L, 1L << 50, Long.MaxValue, -1000L)

test("Timestamp round-trips via InMemory"):
for t <- tsCases do assertEquals(imRead(imHarvest(_.writeTimestamp(t)))(_.readTimestamp()), t)
Expand All @@ -106,7 +106,7 @@ class IoContractExtTest extends munit.FunSuite:
assertEquals(jsonHarvest(_.writeTimestamp(1750000000000L)), "1750000000000")

// ===== Binary =====
private val binCases: Seq[Array[Byte]] =
private lazy val binCases: Seq[Array[Byte]] =
Seq(
Array.empty[Byte],
Array[Byte](1, 2, 3),
Expand Down
2 changes: 0 additions & 2 deletions test/mcodec/JavaHashSetIntTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

package halotukozak.mcodec

import halotukozak.mcodec.MValue.*

import java.util as ju

// Passes on JVM and Scala.js; crashes the Scala Native runtime with
Expand Down