Skip to content

Commit

Permalink
Fix default argument handling for huge case classes (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed May 18, 2021
1 parent 0561495 commit b8ab7ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions core/src/upickle/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ trait Types{ types =>
}
def visitKey(index: Int) = _root_.upickle.core.StringVisitor
protected def storeValueIfNotFound(i: Int, v: Any) = {
if ((found(currentIndex / 64) & (1L << i)) == 0) {
found(currentIndex / 64) |= (1L << i)
if ((found(i / 64) & (1L << i)) == 0) {
found(i / 64) |= (1L << i)
storeAggregatedValue(i, v)
}
}
Expand Down
19 changes: 17 additions & 2 deletions upickle/test/src-2/upickle/TooBigTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ object TooBigTests extends TestSuite {
err.getMessage ==
"missing keys in dictionary: _2, _52, _102, _142 at index 1392"
)

val readWithDefault1 = upickle.default.read[Big150](
written150.replace(",\"_149\":149", "")
)
assert(readWithDefault1 == b150.copy(_149 = -1337))

val readWithDefault2 = upickle.default.read[Big150](
written150.replace("\"_0\":0,", "")
)
assert(readWithDefault2 == b150.copy(_0 = 31337))

val readWithDefault3 = upickle.default.read[Big150](
written150.replace("\"_0\":0,", "").replace(",\"_149\":149", "")
)
assert(readWithDefault3 == b150.copy(_0 = 31337, _149 = -1337))
}
}
// test("hugeFile"){
Expand Down Expand Up @@ -158,7 +173,7 @@ case class Big65(_0: Byte, _1: Byte, _2: Byte, _3: Byte, _4: Byte, _5: Byte, _6:
object Big65{
implicit val b65rw: upickle.default.ReadWriter[Big65] = upickle.default.macroRW
}
case class Big150(_0: Int, _1: Int, _2: Int, _3: Int, _4: Int, _5: Int, _6: Int, _7: Int,
case class Big150(_0: Int = 31337, _1: Int, _2: Int, _3: Int, _4: Int, _5: Int, _6: Int, _7: Int,
_8: Int, _9: Int, _10: Int, _11: Int, _12: Int, _13: Int, _14: Int,
_15: Int, _16: Int, _17: Int, _18: Int, _19: Int, _20: Int, _21: Int,
_22: Int, _23: Int, _24: Int, _25: Int, _26: Int, _27: Int, _28: Int,
Expand All @@ -180,7 +195,7 @@ case class Big150(_0: Int, _1: Int, _2: Int, _3: Int, _4: Int, _5: Int, _6: Int,
_129: Int, _130: Int, _131: Int, _132: Int, _133: Int, _134: Int,
_135: Int, _136: Int, _137: Int, _138: Int, _139: Int, _140: Int,
_141: Int, _142: Int, _143: Int, _144: Int, _145: Int, _146: Int,
_147: Int, _148: Int, _149: Int){
_147: Int, _148: Int, _149: Int = -1337 /*default*/){

// Workaround for https://github.com/scala/scala/pull/9635
override def equals(other: Any): Boolean = other match{
Expand Down

0 comments on commit b8ab7ab

Please sign in to comment.