Skip to content

Commit

Permalink
Bugfix: Scala 3 generics (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgyucht authored and jodersky committed Jan 3, 2022
1 parent 9655b81 commit 1090cc5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion implicits/src-3/upickle/implicits/macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ end extractKey
inline def fieldLabels[T] = ${fieldLabelsImpl[T]}
def fieldLabelsImpl0[T](using Quotes, Type[T]): List[String] =
import quotes.reflect._
val fields: List[Symbol] = TypeTree.of[T].symbol
val fields: List[Symbol] = TypeRepr.of[T].typeSymbol
.primaryConstructor
.paramSymss
.flatten
.filterNot(_.isType)

fields.map{ sym =>
extractKey(sym) match {
Expand Down
24 changes: 24 additions & 0 deletions upickle/test/src/upickle/example/ExampleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ object Custom2{
)
}
}
object Generic {
case class Container[T](a: T)
object Container{
implicit val intRW: RW[Container[Int]] = macroRW
}
}


import KeyedTag._
import Keyed._
Expand Down Expand Up @@ -569,6 +576,23 @@ object ExampleTests extends TestSuite {
writeBinary(Array[Byte](1, 2, 3, 4)) ==> Array(0xc4.toByte, 4, 1, 2, 3, 4)
readBinary[Array[Byte]](Array[Byte](0xc4.toByte, 4, 1, 2, 3, 4)) ==> Array(1, 2, 3, 4)
}
test("generic"){
import upickle.default._
import Generic._
test("read") - {
val containerJson = """{"a":3}"""
val parsed = read[Container[Int]](containerJson)
val expected = Container[Int](3)
assert(parsed == expected)
}

test("write") - {
val original = Container[Int](3)
val serialized = write(original)
val expected = """{"a":3}"""
assert(serialized == expected)
}
}
}
}

Expand Down

0 comments on commit 1090cc5

Please sign in to comment.