Skip to content

Commit 4cbabbd

Browse files
committed
add test for non-opt cases; fix bug
1 parent 379a5a7 commit 4cbabbd

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

packages/candid/src/idl.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,6 @@ test('IDL opt edge cases', () => {
749749
// Motoko: {a = #x } : {a : {#x;#y}}
750750
'opt expected type non-opt on wire',
751751
);
752-
/*
753752
testDecode(
754753
IDL.Record({a: IDL.Opt(IDL.Variant({ x: IDL.Null, y: IDL.Null }))}),
755754
{a: [{x: null}]},
@@ -764,5 +763,4 @@ test('IDL opt edge cases', () => {
764763
// Motoko: {a = #z } : {a : {#x;#y;#z}}
765764
'opt expected, wire type non-opt, extended, with unexpected tag - defaulting',
766765
);
767-
*/
768766
});

packages/candid/src/idl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,13 +950,13 @@ export class OptClass<T> extends ConstructType<[T] | []> {
950950
// try constituent type
951951
const checkpoint = b.save();
952952
try {
953-
const v = this._type.decodeValue(b, wireType)
953+
const v = this._type.decodeValue(b, t)
954954
return [v];
955955
} catch (e : any) {
956956
// decoding failed, but this is opt, so return "null", i.e. []
957957
b.restore(checkpoint);
958958
// skip value at wire type (to advance b)
959-
const skipped = wireType.decodeValue(b, wireType)
959+
const skipped = wireType.decodeValue(b, t)
960960
// return "null"
961961
return [];
962962
}

0 commit comments

Comments
 (0)