From b686d9fb3ccea38347a57fedea1d2bec4738ea7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Mon, 15 Jun 2026 19:54:42 +0200 Subject: [PATCH] Fix derivation compile crash: bump made to 0.1.3, drop `private` from inline derivation helpers - made 0.1.2 -> 0.1.3: 0.1.2 lacked the `containsOnly` given required by `toArrayOf[Boolean]` in `deriveProduct`, so the project did not compile - Drop `private` from the inline helpers in `Derivation`. As `private` members reached through the `this: MCodec.type =>` self-type, inlining synthesized a positionless `Derivation_this.asInstanceOf[...]` cast that crashed the compiler (`assertion failed: position not set`) at every `derives MCodec` call site. All tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) --- project.scala | 2 +- src/mcodec/Derivation.scala | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/project.scala b/project.scala index 3ea42d2..02660d4 100644 --- a/project.scala +++ b/project.scala @@ -1,6 +1,6 @@ //> using scala 3.8.4 -//> using dep io.github.halotukozak::made:0.1.2 +//> using dep io.github.halotukozak::made:0.1.3 //> using test.dep org.scalameta::munit:1.3.3 //> using test.dep org.scalameta::munit-scalacheck:1.3.0 diff --git a/src/mcodec/Derivation.scala b/src/mcodec/Derivation.scala index 29d7ce9..6d04ded 100644 --- a/src/mcodec/Derivation.scala +++ b/src/mcodec/Derivation.scala @@ -14,13 +14,13 @@ trait Derivation: deferred.underlying = built built - transparent inline private def deriveDispatch[T](m: Made.Of[T]): MCodec[T] = inline m match + transparent inline def deriveDispatch[T](m: Made.Of[T]): MCodec[T] = inline m match case pm: Made.ProductOf[T] => deriveProduct[T](pm) case sm: Made.SumOf[T] => deriveSum[T](sm) case tm: Made.TransparentOf[T] => deriveTransparent[T](tm) case gm: Made.SingletonOf[T] => deriveSingleton[T](gm) - inline private def deriveProduct[T](m: Made.ProductOf[T]): MCodec[T] = ProductCodec[T]( + inline def deriveProduct[T](m: Made.ProductOf[T]): MCodec[T] = ProductCodec[T]( compiletime.constValue[m.Label], compiletime.constValueTuple[m.ElemLabels].toArrayOf[String], compiletime.summonAll[Tuple.Map[m.ElemTypes, MCodec]].toArrayOf[MCodec[Any]](using containsOnly.refl), @@ -43,12 +43,12 @@ trait Derivation: .toArrayOf[MCodec[Any]](using containsOnly.refl), ) - inline private def isOptionFlags[Elems <: Tuple]: List[Boolean] = inline compiletime.erasedValue[Elems] match + inline def isOptionFlags[Elems <: Tuple]: List[Boolean] = inline compiletime.erasedValue[Elems] match case _: EmptyTuple => Nil case _: (Option[?] *: tail) => true :: isOptionFlags[tail] case _: (head *: tail) => false :: isOptionFlags[tail] - inline private def deriveSum[T](m: Made.SumOf[T]): MCodec[T] = + inline def deriveSum[T](m: Made.SumOf[T]): MCodec[T] = inline if m.hasAnnotation[mcodec.annotation.flatten] then FlatSumCodec[T]( compiletime.constValue[m.Label], @@ -68,7 +68,7 @@ trait Derivation: ) // Compile-time guard (>1 @defaultCase is an error) + index selection. - transparent inline private def defaultCaseIdx(inline flags: Tuple): Int = inline flags match + transparent inline def defaultCaseIdx(inline flags: Tuple): Int = inline flags match case _: EmptyTuple => -1 case fs: (head *: tail) => inline if compiletime.constValue[head & Boolean] then @@ -79,13 +79,13 @@ trait Derivation: case -1 => -1 case n => n + 1 - inline private def rejectMoreDefaults(inline flags: Tuple): Unit = inline flags match + inline def rejectMoreDefaults(inline flags: Tuple): Unit = inline flags match case _: EmptyTuple => () case fs: (head *: tail) => inline if compiletime.constValue[head & Boolean] then compiletime.error("more than one @defaultCase in hierarchy") else rejectMoreDefaults(fs.tail) - inline private def summonOrDeriveCases[Elems <: Tuple]: List[MCodec[Any]] = + inline def summonOrDeriveCases[Elems <: Tuple]: List[MCodec[Any]] = inline compiletime.erasedValue[Elems] match case _: EmptyTuple => Nil case _: (head *: tail) => @@ -95,9 +95,9 @@ trait Derivation: c.asInstanceOf[MCodec[Any]] :: summonOrDeriveCases[tail] - inline private def deriveSingleton[T](m: Made.SingletonOf[T]): MCodec[T] = SingletonCodec[T](m.value) + inline def deriveSingleton[T](m: Made.SingletonOf[T]): MCodec[T] = SingletonCodec[T](m.value) - inline private def deriveTransparent[T](m: Made.TransparentOf[T]): MCodec[T] = TransparentCodec( + inline def deriveTransparent[T](m: Made.TransparentOf[T]): MCodec[T] = TransparentCodec( m.wrap, m.unwrap, compiletime.summonInline[MCodec[m.ElemType]],