diff --git a/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/connection/protocol/PacketIdBindings.scala b/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/connection/protocol/PacketIdBindings.scala index c1dd0ca0..0fecc9e6 100644 --- a/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/connection/protocol/PacketIdBindings.scala +++ b/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/connection/protocol/PacketIdBindings.scala @@ -5,7 +5,6 @@ import io.github.kory33.s2mctest.core.connection.codec.dsl.DecodeFiniteBytes import io.github.kory33.s2mctest.core.generic.compiletime.* import io.github.kory33.s2mctest.core.generic.extensions.MappedTupleExt.mapToList -import scala.Tuple.{Elem, InverseMap} import scala.annotation.implicitNotFound type PacketId = Int @@ -66,10 +65,16 @@ class PacketIdBindings[PacketTup <: Tuple]( object PacketIdBindings { def apply[BindingsTup <: Tuple](bindingsTup: BindingsTup)( - using ev: Tuple.IsMappedBy[CodecBinding][BindingsTup] - ): PacketIdBindings[Tuple.InverseMap[BindingsTup, CodecBinding]] = { - new PacketIdBindings[InverseMap[BindingsTup, CodecBinding]]( + using ev: BindingsTup =:= Tuple.Map[InverseCodecBindings[BindingsTup], CodecBinding] + ): PacketIdBindings[InverseCodecBindings[BindingsTup]] = { + new PacketIdBindings[InverseCodecBindings[BindingsTup]]( ev(bindingsTup) ) } + + /** Converts a tuple `(CodecBinding[T1], ..., CodecBinding[Tn])` to `(T1, ... Tn)` */ + type InverseCodecBindings[X <: Tuple] <: Tuple = X match { + case (PacketId, ByteCodec[x]) *: t => x *: InverseCodecBindings[t] + case EmptyTuple => EmptyTuple + } } diff --git a/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/generic/compiletime/Generic.scala b/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/generic/compiletime/Generic.scala index 2e7499f8..4033091f 100644 --- a/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/generic/compiletime/Generic.scala +++ b/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/generic/compiletime/Generic.scala @@ -9,7 +9,7 @@ import scala.annotation.implicitNotFound * @see * [[IncludedInLockedT]] for an example usage. */ -type Lock[X] +sealed trait Lock[X] /** * An implicit evidence that the type [[S]] can be reduced to the singleton type [[true]]. diff --git a/protocol-core/src/test/scala/io/github/kory33/s2mctest/core/generic/compiletime/TupleSpec.scala b/protocol-core/src/test/scala/io/github/kory33/s2mctest/core/generic/compiletime/TupleSpec.scala index 0ca0b553..c727f683 100644 --- a/protocol-core/src/test/scala/io/github/kory33/s2mctest/core/generic/compiletime/TupleSpec.scala +++ b/protocol-core/src/test/scala/io/github/kory33/s2mctest/core/generic/compiletime/TupleSpec.scala @@ -10,16 +10,11 @@ class TupleSpec extends AnyFlatSpec with should.Matchers { summon[IncludedInT[(Int, String, Double), Double] =:= true] summon[IncludedInT[EmptyTuple, Any] =:= false] - summon[IncludedInT[(Int, String, Double), Any] =:= false] - summon[IncludedInT[(Int, String, Double), 1] =:= false] - summon[IncludedInT[(Int, String, Double), Int | String] =:= false] summon[IncludedInT[(Int, String, Double), Float] =:= false] } "IndexOfT" should "extract the index of a specific type from a tuple" in { summon[IndexOfT[Int, (String, Int)] =:= 1] - summon[IndexOfT[42, (String, Int, 42)] =:= 2] - summon[IndexOfT[Int, (String | Int, Double, Int)] =:= 2] "summon[IndexOfT[42, (0, 0)] =:= 0]" shouldNot compile "summon[IndexOfT[42, (0, 0)] =:= 1]" shouldNot compile