Skip to content

Commit 392dc3c

Browse files
committed
remove unused apply method from Castable, add codec to BaseOpaque
1 parent b6a5b95 commit 392dc3c

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

Diff for: core/src/main/scala/com/avsystem/commons/opaque/BaseOpaque.scala

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ package com.avsystem.commons
22
package opaque
33

44
import com.avsystem.commons.opaque.Castable.<:>
5+
import com.avsystem.commons.serialization.GenCodec
56

67
private[opaque] trait BaseOpaque[From] extends Castable.Ops {
78
trait Tag
89
type Type
910

10-
implicit protected final val castable: From <:> Type = new Castable[From, Type]
11-
1211
def apply(value: From): Type
12+
13+
14+
implicit protected final val castable: From <:> Type = new Castable[From, Type]
15+
implicit final def codec(implicit fromCodec: GenCodec[From]): GenCodec[Type] = wrapF(fromCodec)
1316
}

Diff for: core/src/main/scala/com/avsystem/commons/opaque/Castable.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.avsystem.commons
22
package opaque
33

4-
private[opaque] final class Castable[A, B] {
5-
@inline def apply(a: A): B = a.asInstanceOf[B]
6-
}
4+
private[opaque] final class Castable[A, B]
75
private[opaque] object Castable {
86
type <:>[A, B] = Castable[A, B]
97
def apply[A, B](implicit ev: A <:> B): Castable[A, B] = ev

Diff for: core/src/test/scala/com/avsystem/commons/serialization/CodecTestData.scala

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package serialization
44
import com.avsystem.commons.annotation.AnnotationAggregate
55
import com.avsystem.commons.meta.{AutoOptionalParams, MacroInstances}
66
import com.avsystem.commons.misc.{AutoNamedEnum, NamedEnumCompanion, TypedKey}
7+
import com.avsystem.commons.opaque.{Opaque, Subopaque}
78

89
import scala.annotation.meta.getter
910

@@ -134,6 +135,9 @@ object CodecTestData {
134135
@transparent case class StringId(id: String)
135136
object StringId extends TransparentWrapperCompanion[String, StringId]
136137

138+
object SomeOpaque extends Opaque.Default[Int]
139+
object SomeSubopaque extends Subopaque.Default[Int]
140+
137141
trait HasSomeStr {
138142
@name("some.str") def str: String
139143
@generated def someStrLen: Int = str.length

Diff for: core/src/test/scala/com/avsystem/commons/serialization/GenCodecRoundtripTest.scala

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ abstract class GenCodecRoundtripTest extends AbstractCodecTest {
7272
testRoundtrip(StringId("lolfuu"), "lolfuu")
7373
}
7474

75+
test("opaque and subopaque") {
76+
testRoundtrip(SomeOpaque(42))
77+
testRoundtrip(SomeSubopaque(42))
78+
}
79+
7580
test("case class") {
7681
testRoundtrip(SomeCaseClass("dafuq", List(1, 2, 3)))
7782
}

0 commit comments

Comments
 (0)