{"record":{"id":"3cac7f65b8482741","repo":"go-delve/delve","slug":"shift-count-type-s-must-be-unsigned-integer","errorCode":null,"errorMessage":"shift count type %s, must be unsigned integer","messagePattern":"shift count type (.+?), must be unsigned integer","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2449,"sourceCode":"\n\tif yv == nilVariable {\n\t\treturn nil, negotiateTypeNil(op, xv)\n\t}\n\n\tif op == token.SHR || op == token.SHL {\n\t\tif xv.Value == nil || xv.Value.Kind() != constant.Int {\n\t\t\treturn nil, fmt.Errorf(\"shift of type %s\", xv.Kind)\n\t\t}\n\n\t\tswitch yv.Kind {\n\t\tcase reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:\n\t\t\t// ok\n\t\tcase reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:\n\t\t\tif constant.Sign(yv.Value) < 0 {\n\t\t\t\treturn nil, errors.New(\"shift count must not be negative\")\n\t\t\t}\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"shift count type %s, must be unsigned integer\", yv.Kind.String())\n\t\t}\n\n\t\treturn xv.DwarfType, nil\n\t}\n\n\tif xv.DwarfType == nil && yv.DwarfType == nil {\n\t\treturn nil, nil\n\t}\n\n\tif xv.DwarfType != nil && yv.DwarfType != nil {\n\t\tif xv.DwarfType.String() != yv.DwarfType.String() {\n\t\t\treturn nil, fmt.Errorf(\"mismatched types %q and %q\", xv.DwarfType.String(), yv.DwarfType.String())\n\t\t}\n\t\treturn xv.DwarfType, nil\n\t} else if xv.DwarfType != nil && yv.DwarfType == nil {\n\t\tif err := yv.isType(xv.DwarfType, xv.Kind); err != nil {\n\t\t\treturn nil, err\n\t\t}","sourceCodeStart":2431,"sourceCodeEnd":2467,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2431-L2467","documentation":"Delve's expression evaluator requires the right-hand operand of a shift (<< or >>) to be an unsigned integer. When the shift-count variable's reflect.Kind is not one of the signed int kinds that passed the earlier checks (i.e. it's a float, string, struct, etc.), the evaluator rejects it with this message. It mirrors Go's compile-time rule that shift counts must be unsigned integers.","triggerScenarios":"Evaluating an expression like `x << y` in the debugger where y is a negative int (handled separately), a float64, or a non-numeric kind such as string, bool, slice or struct. Reached via EvalScope.evaluateBinaryOp with op token.SHL/token.SHR and the shift-count variable's Kind outside the int/uint set.","commonSituations":"Debugging session where the user writes `buf >> 4.0` or `flags << someStringVar`; typical for someone testing bit-manipulation logic interactively and forgetting the operand types differ from what they assume in source.","solutions":["Cast the shift count to an unsigned integer: `x << uint(y)`.","If the count is a float, convert to int first: `x << uint(int(f))`.","Inspect the count variable (`print y`) to confirm its type is what you expect."],"exampleFix":"// before\np x << y        // y is float64\n// after\np x << uint(y)","handlingStrategy":"validation","validationCode":"// before: x << y\nif v, err := eval(\"y\"); err == nil {\n    switch v.Kind {\n    case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:\n        // ok\n    default:\n        y = uint(y) // cast the shift count before shifting\n    }\n}","typeGuard":"func isUnsignedKind(k reflect.Kind) bool {\n    switch k {\n    case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Always cast shift counts explicitly: uint(n).","Never shift by float or signed values without conversion.","Print the count variable in Delve before using it in a shift expression."],"tags":["debugger","expression-evaluation","type-mismatch"],"backgroundTag":"invalid-shift-count-type","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}