Skip to content

Commit 7b5f1db

Browse files
committed
fix cast int* to uint*
1 parent a4e2eab commit 7b5f1db

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

internal/value/value.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,18 +801,66 @@ func (v int8Value) castTo(dst interface{}) error {
801801
case *int64:
802802
*vv = int64(v)
803803

804+
return nil
805+
806+
case *uint64:
807+
if v < 0 {
808+
return xerrors.WithStackTrace(fmt.Errorf(
809+
"%w '%+v' (type '%s') to '%T' destination",
810+
ErrCannotCast, v, v.Type().Yql(), vv,
811+
))
812+
}
813+
814+
*vv = uint64(v)
815+
804816
return nil
805817
case *int32:
806818
*vv = int32(v)
807819

820+
return nil
821+
822+
case *uint32:
823+
if v < 0 {
824+
return xerrors.WithStackTrace(fmt.Errorf(
825+
"%w '%+v' (type '%s') to '%T' destination",
826+
ErrCannotCast, v, v.Type().Yql(), vv,
827+
))
828+
}
829+
830+
*vv = uint32(v)
831+
808832
return nil
809833
case *int16:
810834
*vv = int16(v)
811835

836+
return nil
837+
838+
case *uint16:
839+
if v < 0 {
840+
return xerrors.WithStackTrace(fmt.Errorf(
841+
"%w '%+v' (type '%s') to '%T' destination",
842+
ErrCannotCast, v, v.Type().Yql(), vv,
843+
))
844+
}
845+
846+
*vv = uint16(v)
847+
812848
return nil
813849
case *int8:
814850
*vv = int8(v)
815851

852+
return nil
853+
854+
case *uint8:
855+
if v < 0 {
856+
return xerrors.WithStackTrace(fmt.Errorf(
857+
"%w '%+v' (type '%s') to '%T' destination",
858+
ErrCannotCast, v, v.Type().Yql(), vv,
859+
))
860+
}
861+
862+
*vv = uint8(v)
863+
816864
return nil
817865
case *float64:
818866
*vv = float64(v)
@@ -929,14 +977,50 @@ func (v int32Value) castTo(dst interface{}) error {
929977
case *int64:
930978
*vv = int64(v)
931979

980+
return nil
981+
982+
case *uint64:
983+
if v < 0 {
984+
return xerrors.WithStackTrace(fmt.Errorf(
985+
"%w '%+v' (type '%s') to '%T' destination",
986+
ErrCannotCast, v, v.Type().Yql(), vv,
987+
))
988+
}
989+
990+
*vv = uint64(v)
991+
932992
return nil
933993
case *int:
934994
*vv = int(v)
935995

996+
return nil
997+
998+
case *uint:
999+
if v < 0 {
1000+
return xerrors.WithStackTrace(fmt.Errorf(
1001+
"%w '%+v' (type '%s') to '%T' destination",
1002+
ErrCannotCast, v, v.Type().Yql(), vv,
1003+
))
1004+
}
1005+
1006+
*vv = uint(v)
1007+
9361008
return nil
9371009
case *int32:
9381010
*vv = int32(v)
9391011

1012+
return nil
1013+
1014+
case *uint32:
1015+
if v < 0 {
1016+
return xerrors.WithStackTrace(fmt.Errorf(
1017+
"%w '%+v' (type '%s') to '%T' destination",
1018+
ErrCannotCast, v, v.Type().Yql(), vv,
1019+
))
1020+
}
1021+
1022+
*vv = uint32(v)
1023+
9401024
return nil
9411025
case *float64:
9421026
*vv = float64(v)
@@ -991,6 +1075,18 @@ func (v int64Value) castTo(dst interface{}) error {
9911075
case *int64:
9921076
*vv = int64(v)
9931077

1078+
return nil
1079+
1080+
case *uint64:
1081+
if v < 0 {
1082+
return xerrors.WithStackTrace(fmt.Errorf(
1083+
"%w '%+v' (type '%s') to '%T' destination",
1084+
ErrCannotCast, v, v.Type().Yql(), vv,
1085+
))
1086+
}
1087+
1088+
*vv = uint64(v)
1089+
9941090
return nil
9951091
case *float64:
9961092
*vv = float64(v)

0 commit comments

Comments
 (0)