Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rlp/rlpgen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ func (op sliceOp) genDecode(ctx *genContext) (string, string) {
}

func (bctx *buildContext) makeOp(name *types.Named, typ types.Type, tags rlpstruct.Tags) (op, error) {
switch typ := typ.(type) {
switch typ := types.Unalias(typ).(type) {
case *types.Named:
if isBigInt(typ) {
return bigIntOp{}, nil
Expand Down
2 changes: 1 addition & 1 deletion rlp/rlpgen/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func init() {
}
}

var tests = []string{"uints", "nil", "rawvalue", "optional", "bigint", "uint256"}
var tests = []string{"uints", "nil", "rawvalue", "optional", "bigint", "uint256", "alias"}

func TestOutput(t *testing.T) {
for _, test := range tests {
Expand Down
22 changes: 22 additions & 0 deletions rlp/rlpgen/testdata/alias.in.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// -*- mode: go -*-

package test

import (
"math/big"
"github.com/holiman/uint256"
)

// Alias types chosen because their originals have special handling that is easy
// to spot when inspecting generated output.
type (
Big = big.Int
// Demonstrate recursive unaliasing
intermediate = uint256.Int
Uint256 = intermediate
)

type Test struct {
BigAlias Big
Uint256Alias Uint256
}
43 changes: 43 additions & 0 deletions rlp/rlpgen/testdata/alias.out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package test

import "github.com/ava-labs/libevm/rlp"
import "github.com/holiman/uint256"
import "io"

func (obj *Test) EncodeRLP(_w io.Writer) error {
w := rlp.NewEncoderBuffer(_w)
_tmp0 := w.List()
if obj.BigAlias.Sign() == -1 {
return rlp.ErrNegativeBigInt
}
w.WriteBigInt(&obj.BigAlias)
w.WriteUint256(&obj.Uint256Alias)
w.ListEnd(_tmp0)
return w.Flush()
}

func (obj *Test) DecodeRLP(dec *rlp.Stream) error {
var _tmp0 Test
{
if _, err := dec.List(); err != nil {
return err
}
// BigAlias:
_tmp1, err := dec.BigInt()
if err != nil {
return err
}
_tmp0.BigAlias = (*_tmp1)
// Uint256Alias:
var _tmp2 uint256.Int
if err := dec.ReadUint256(&_tmp2); err != nil {
return err
}
_tmp0.Uint256Alias = _tmp2
if err := dec.ListEnd(); err != nil {
return err
}
}
*obj = _tmp0
return nil
}