@@ -373,6 +373,30 @@ func (op uint256Op) genDecode(ctx *genContext) (string, string) {
373373 return result , b .String ()
374374}
375375
376+ func (bctx * buildContext ) makeNamedBasicOp (named * types.Named ) (op , error ) {
377+ underlying := named .Underlying ()
378+ basic , ok := underlying .(* types.Basic )
379+ if ! ok {
380+ return nil , fmt .Errorf ("expected basic type, got %T" , underlying )
381+ }
382+
383+ // Use the existing makeBasicOp function to get the base operation
384+ baseOp , err := bctx .makeBasicOp (basic )
385+ if err != nil {
386+ return nil , err
387+ }
388+
389+ // Cast to basicOp and modify the typ field to use the named type
390+ op := baseOp .(basicOp )
391+ op .typ = named // Use the named type as the main type instead of the underlying basic type
392+
393+ // For decoding, we want to decode as the underlying basic type and convert to named type
394+ // So we need to set decResultType to the underlying basic type
395+ op .decResultType = basic
396+
397+ return op , nil
398+ }
399+
376400// encoderDecoderOp handles rlp.Encoder and rlp.Decoder.
377401// In order to be used with this, the type must implement both interfaces.
378402// This restriction may be lifted in the future by creating separate ops for
@@ -684,6 +708,9 @@ func (bctx *buildContext) makeOp(name *types.Named, typ types.Type, tags rlpstru
684708 if typ == bctx .rawValueType {
685709 return bctx .makeRawValueOp (), nil
686710 }
711+ if isNamedWithBasicUnderlying (typ ) {
712+ return bctx .makeNamedBasicOp (typ )
713+ }
687714 if bctx .isDecoder (typ ) {
688715 return nil , fmt .Errorf ("type %v implements rlp.Decoder with non-pointer receiver" , typ )
689716 }
0 commit comments