Skip to content

Commit 79bf8eb

Browse files
committed
[Tolk] Fix unpacking RemainingBitsAndRefs when it's not the last
1 parent c8a5b1b commit 79bf8eb

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

tolk-tester/tests/pack-unpack-2.tolk

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,12 @@ struct ReadWriteMid<T> {
375375
f3: coins;
376376
}
377377

378+
struct WithTwoRestFields {
379+
i32: int32;
380+
rest1: RemainingBitsAndRefs;
381+
rest2: RemainingBitsAndRefs;
382+
}
383+
378384

379385

380386
// ---------------------------------------------
@@ -649,6 +655,20 @@ fun test_MidIsBuilderOrBitsN() {
649655
return (r.f1, mid.remainingBitsCount(), mid.loadAny<int32>(), mid.remainingBitsCount(), r.f3);
650656
}
651657

658+
@method_id(226)
659+
fun test_MultipleRemainers() {
660+
val m = WithTwoRestFields.fromSlice(stringHexToSlice("00000001FFFF"));
661+
return (m.i32, m.rest1.remainingBitsCount(), m.rest2.remainingBitsCount());
662+
}
663+
664+
@method_id(227)
665+
fun test_mutatingRemainder() {
666+
var cs = stringHexToSlice("00000001FFFF");
667+
val obj = cs.loadAny<IntAndRestInlineCell>();
668+
cs.assertEnd();
669+
return obj.rest.remainingBitsCount();
670+
}
671+
652672

653673
fun main() {
654674
var t: JustInt32 = { value: 10 };
@@ -686,4 +706,6 @@ fun main() {
686706
@testcase | 223 | | 10 55 (null)
687707
@testcase | 224 | | 60 50000000 5 9 123 -1
688708
@testcase | 225 | | 5 40 65535 8 50000000
709+
@testcase | 226 | | 1 16 0
710+
@testcase | 227 | | 16
689711
*/

tolk/pack-unpack-serializers.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,10 @@ struct S_RemainingBitsAndRefs final : ISerializer {
419419
}
420420

421421
std::vector<var_idx_t> unpack(const UnpackContext* ctx, CodeBlob& code, SrcLocation loc) override {
422-
return ctx->ir_slice;
422+
std::vector ir_rem_slice = code.create_tmp_var(TypeDataSlice::create(), loc, "(remainder)");
423+
code.emplace_back(loc, Op::_Let, ir_rem_slice, ctx->ir_slice);
424+
code.emplace_back(loc, Op::_Call, ctx->ir_slice, std::vector<var_idx_t>{}, lookup_function("createEmptySlice"));
425+
return ir_rem_slice;
423426
}
424427

425428
void skip(const UnpackContext* ctx, CodeBlob& code, SrcLocation loc) override {

0 commit comments

Comments
 (0)