diff --git a/enumz-chimney/src/test/scala/io/scalaland/enumz/chimney/EnumPartialTransformerSpec.scala b/enumz-chimney/src/test/scala/io/scalaland/enumz/chimney/EnumPartialTransformerSpec.scala index da6d8e3..b0b92e1 100644 --- a/enumz-chimney/src/test/scala/io/scalaland/enumz/chimney/EnumPartialTransformerSpec.scala +++ b/enumz-chimney/src/test/scala/io/scalaland/enumz/chimney/EnumPartialTransformerSpec.scala @@ -8,18 +8,18 @@ class EnumPartialTransformerSpec extends munit.FunSuite { test("Convert between enums") { assertEquals( - Enum[TestEnumeration.TestEnumeration].values.transformInto[Vector[TestEnumeratum]], - Enum[TestEnumeratum].values + Enum[TestEnumeration.TestEnumeration].values.transformIntoPartial[Vector[TestEnumeratum]].asOption, + Some(Enum[TestEnumeratum].values) ) assertEquals( - Enum[TestEnumeratum].values.transformInto[Vector[TestSumType]], - Enum[TestSumType].values + Enum[TestEnumeratum].values.transformIntoPartial[Vector[TestSumType]].asOption, + Some(Enum[TestSumType].values) ) assertEquals( - Enum[TestSumType].values.transformInto[Vector[TestEnumeration.TestEnumeration]], - Enum[TestEnumeration.TestEnumeration].values + Enum[TestSumType].values.transformIntoPartial[Vector[TestEnumeration.TestEnumeration]].asOption, + Some(Enum[TestEnumeration.TestEnumeration].values) ) } } diff --git a/enumz/src/main/scala-2/io/scalaland/enumz/EnumerationImplicits.scala b/enumz/src/main/scala-2/io/scalaland/enumz/EnumerationImplicits.scala index 85aa18e..2354ea3 100644 --- a/enumz/src/main/scala-2/io/scalaland/enumz/EnumerationImplicits.scala +++ b/enumz/src/main/scala-2/io/scalaland/enumz/EnumerationImplicits.scala @@ -2,7 +2,7 @@ package io.scalaland.enumz import scala.language.experimental.macros -trait EnumerationImplicits { +private[enumz] trait EnumerationImplicits { implicit def enumerationEnum[E <: Enumeration#Value]: Enum[E] = macro internal.EnumerationMacros.`enum`[E] } diff --git a/enumz/src/main/scala-2/io/scalaland/enumz/EnumeratumImplicits.scala b/enumz/src/main/scala-2/io/scalaland/enumz/EnumeratumImplicits.scala index c7f849f..5acdd77 100644 --- a/enumz/src/main/scala-2/io/scalaland/enumz/EnumeratumImplicits.scala +++ b/enumz/src/main/scala-2/io/scalaland/enumz/EnumeratumImplicits.scala @@ -2,7 +2,7 @@ package io.scalaland.enumz import scala.language.experimental.macros -trait EnumeratumImplicits { +private[enumz] trait EnumeratumImplicits { implicit def enumeratumEnum[E <: enumeratum.EnumEntry]: Enum[E] = macro internal.EnumeratumMacros.`enum`[E] } diff --git a/enumz/src/main/scala-2/io/scalaland/enumz/SumTypeEnumImplicits.scala b/enumz/src/main/scala-2/io/scalaland/enumz/SumTypeEnumImplicits.scala index 7384a1a..c83d523 100644 --- a/enumz/src/main/scala-2/io/scalaland/enumz/SumTypeEnumImplicits.scala +++ b/enumz/src/main/scala-2/io/scalaland/enumz/SumTypeEnumImplicits.scala @@ -2,7 +2,7 @@ package io.scalaland.enumz import scala.language.experimental.macros -trait SumTypeEnumImplicits { +private[enumz] trait SumTypeEnumImplicits { implicit def sumTypeEnum[E]: Enum[E] = macro internal.SumTypeEnumMacros.`enum`[E] } diff --git a/enumz/src/main/scala-2/io/scalaland/enumz/internal/SumTypeEnumMacros.scala b/enumz/src/main/scala-2/io/scalaland/enumz/internal/SumTypeEnumMacros.scala index fc73701..5de0984 100644 --- a/enumz/src/main/scala-2/io/scalaland/enumz/internal/SumTypeEnumMacros.scala +++ b/enumz/src/main/scala-2/io/scalaland/enumz/internal/SumTypeEnumMacros.scala @@ -1,7 +1,7 @@ package io.scalaland.enumz.internal import io.scalaland.enumz.Enum -import scala.reflect.macros.blackbox.* +import scala.reflect.macros.whitebox.* object SumTypeEnumMacros { @@ -18,7 +18,7 @@ object SumTypeEnumMacros { val order = Ordering.fromLessThan[Position]((a, b) => a.line < b.line || (a.line == b.line && a.column < b.column)) val children: List[CSymbol] = symbol.knownDirectSubclasses.toList.sortBy(_.pos)(order) if (!children.forall(_.isModuleClass)) { - c.abort(c.enclosingPosition, "All children must be (case) objects.") + c.abort(c.enclosingPosition, s"All children of ${weakTypeOf[E].dealias} must be (case) objects.") } val sourceModuleRef: CSymbol => Ident = sym => Ident(sym.asInstanceOf[ISymbol].sourceModule.asInstanceOf[CSymbol]) diff --git a/enumz/src/main/scala-3/io/scalaland/enumz/EnumerationImplicits.scala b/enumz/src/main/scala-3/io/scalaland/enumz/EnumerationImplicits.scala index 36a0f29..097fc9c 100644 --- a/enumz/src/main/scala-3/io/scalaland/enumz/EnumerationImplicits.scala +++ b/enumz/src/main/scala-3/io/scalaland/enumz/EnumerationImplicits.scala @@ -1,6 +1,6 @@ package io.scalaland.enumz -trait EnumerationImplicits { +private[enumz] trait EnumerationImplicits { inline given enumerationEnum[E <: Enumeration#Value]: Enum[E] = ${ internal.EnumerationMacros.`enum`[E] } } diff --git a/enumz/src/main/scala-3/io/scalaland/enumz/EnumeratumImplicits.scala b/enumz/src/main/scala-3/io/scalaland/enumz/EnumeratumImplicits.scala index 3f99acc..afe8dc0 100644 --- a/enumz/src/main/scala-3/io/scalaland/enumz/EnumeratumImplicits.scala +++ b/enumz/src/main/scala-3/io/scalaland/enumz/EnumeratumImplicits.scala @@ -1,6 +1,6 @@ package io.scalaland.enumz -trait EnumeratumImplicits { +private[enumz] trait EnumeratumImplicits { inline given enumeratumEnum[E <: enumeratum.EnumEntry]: Enum[E] = ${ internal.EnumeratumMacros.`enum`[E] } } diff --git a/enumz/src/main/scala-3/io/scalaland/enumz/SumTypeEnumImplicits.scala b/enumz/src/main/scala-3/io/scalaland/enumz/SumTypeEnumImplicits.scala index a177970..1dcfca0 100644 --- a/enumz/src/main/scala-3/io/scalaland/enumz/SumTypeEnumImplicits.scala +++ b/enumz/src/main/scala-3/io/scalaland/enumz/SumTypeEnumImplicits.scala @@ -1,6 +1,6 @@ package io.scalaland.enumz -trait SumTypeEnumImplicits { +private[enumz] trait SumTypeEnumImplicits { - inline given sumTypeEnum[E]: Enum[E] = ${ internal.SumTypeEnumMacros.`enum`[E] } + transparent inline given sumTypeEnum[E]: Enum[E] = ${ internal.SumTypeEnumMacros.`enum`[E] } } diff --git a/enumz/src/main/scala-3/io/scalaland/enumz/internal/SumTypeEnumMacros.scala b/enumz/src/main/scala-3/io/scalaland/enumz/internal/SumTypeEnumMacros.scala index 1cd67b1..e835c35 100644 --- a/enumz/src/main/scala-3/io/scalaland/enumz/internal/SumTypeEnumMacros.scala +++ b/enumz/src/main/scala-3/io/scalaland/enumz/internal/SumTypeEnumMacros.scala @@ -19,7 +19,7 @@ object SumTypeEnumMacros { def extractRecursively(sym: Symbol): List[Symbol] = if sym.flags.is(Flags.Sealed) then sym.children.flatMap(extractRecursively) else if sym.flags.is(Flags.Enum) || sym.flags.is(Flags.Module) then List(sym) - else report.errorAndAbort("All children must be (case) objects.") + else report.errorAndAbort(s"All children of ${E.show} must be (case) objects.") given Ordering[Option[Position]] = Ordering.Option(Ordering.fromLessThan[Position] { (a, b) => a.startLine < b.startLine || (a.startLine == b.startLine && a.startColumn < b.startColumn) diff --git a/enumz/src/main/scala/io/scalaland/enumz/Enum.scala b/enumz/src/main/scala/io/scalaland/enumz/Enum.scala index 75865e2..c6b8e8b 100644 --- a/enumz/src/main/scala/io/scalaland/enumz/Enum.scala +++ b/enumz/src/main/scala/io/scalaland/enumz/Enum.scala @@ -23,11 +23,12 @@ trait Enum[E] extends Dynamic { def selectDynamic(name: String): E = withName(name) } -object Enum extends Implicits { +object Enum extends Implicits0 { def apply[E](implicit `enum`: Enum[E]): Enum[E] = `enum` } -trait Implicits extends JavaEnumImplicits with EnumerationImplicits with EnumeratumImplicits with LowPriorityImplicits - -trait LowPriorityImplicits extends SumTypeEnumImplicits +private[enumz] trait Implicits0 extends JavaEnumImplicits with Implicits1 +private[enumz] trait Implicits1 extends EnumerationImplicits with Implicits2 +private[enumz] trait Implicits2 extends EnumeratumImplicits with Implicits3 +private[enumz] trait Implicits3 extends SumTypeEnumImplicits diff --git a/enumz/src/main/scalajs/io/scalaland/enumz/JavaEnumImplicits.scala b/enumz/src/main/scalajs/io/scalaland/enumz/JavaEnumImplicits.scala index 6faa676..9afa406 100644 --- a/enumz/src/main/scalajs/io/scalaland/enumz/JavaEnumImplicits.scala +++ b/enumz/src/main/scalajs/io/scalaland/enumz/JavaEnumImplicits.scala @@ -1,4 +1,4 @@ package io.scalaland.enumz // empty trait made to simplify composition of implicits' traits in shared part -trait JavaEnumImplicits +private[enumz] trait JavaEnumImplicits diff --git a/enumz/src/main/scalajvm-2/io/scalaland/enumz/JavaEnumImplicits.scala b/enumz/src/main/scalajvm-2/io/scalaland/enumz/JavaEnumImplicits.scala index b2da3e2..49b0c71 100644 --- a/enumz/src/main/scalajvm-2/io/scalaland/enumz/JavaEnumImplicits.scala +++ b/enumz/src/main/scalajvm-2/io/scalaland/enumz/JavaEnumImplicits.scala @@ -2,7 +2,7 @@ package io.scalaland.enumz import scala.language.experimental.macros -trait JavaEnumImplicits { +private[enumz] trait JavaEnumImplicits { implicit def javaEnumEnum[E <: java.lang.Enum[E]]: Enum[E] = macro internal.JavaEnumMacros.`enum`[E] } diff --git a/enumz/src/main/scalajvm-3/io/scalaland/enumz/JavaEnumImplicits.scala b/enumz/src/main/scalajvm-3/io/scalaland/enumz/JavaEnumImplicits.scala index 427a37b..4eeb6e7 100644 --- a/enumz/src/main/scalajvm-3/io/scalaland/enumz/JavaEnumImplicits.scala +++ b/enumz/src/main/scalajvm-3/io/scalaland/enumz/JavaEnumImplicits.scala @@ -1,4 +1,4 @@ package io.scalaland.enumz // Java Enums are handled by sealed/enum macro -trait JavaEnumImplicits +private[enumz] trait JavaEnumImplicits diff --git a/enumz/src/main/scalanative/io/scalaland/enumz/JavaEnumImplicits.scala b/enumz/src/main/scalanative/io/scalaland/enumz/JavaEnumImplicits.scala index 6faa676..9afa406 100644 --- a/enumz/src/main/scalanative/io/scalaland/enumz/JavaEnumImplicits.scala +++ b/enumz/src/main/scalanative/io/scalaland/enumz/JavaEnumImplicits.scala @@ -1,4 +1,4 @@ package io.scalaland.enumz // empty trait made to simplify composition of implicits' traits in shared part -trait JavaEnumImplicits +private[enumz] trait JavaEnumImplicits