{"record":{"id":"872e30627f9bb23f","repo":"go-delve/delve","slug":"shift-of-type-s","errorCode":null,"errorMessage":"shift of type %s","messagePattern":"shift of type (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2438,"sourceCode":"\t\tr.Value = rc\n\t\tstack.push(r)\n\t\treturn\n\t}\n\tstack.push(newConstant(rc, xv.bi, xv.mem))\n}\n\nfunc negotiateType(op token.Token, xv, yv *Variable) (godwarf.Type, error) {\n\tif xv == nilVariable {\n\t\treturn nil, negotiateTypeNil(op, yv)\n\t}\n\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","sourceCodeStart":2420,"sourceCodeEnd":2456,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2420-L2456","documentation":"Thrown by negotiateType (binary op type negotiation) when evaluating a shift expression x << y or x >> y whose left operand is not a constant integer: xv.Value is nil or its kind is not constant.Int. Shifts are only defined on integers, so Delve rejects floats, strings, bools, and unevaluatable operands with the left operand's reflect kind in the message.","triggerScenarios":"Evaluating `x << y` at the debugger prompt or in a breakpoint condition where x is a float, string, bool, or a variable with no loaded value (nil constant) — e.g. `1.5 << 2` or `s << 1` for a string s. (The right operand's kind is checked separately in the following switch.)","commonSituations":"Shifts in breakpoint conditions where the left variable is optimized out (nil value), accidental shift on a float counter, or shifting string/bool variables due to a typo in the expression.","solutions":["Check the left operand with `print x`; apply shifts only to integer variables or literals.","Convert a float to an int first if appropriate (e.g. `int(f) << 2`).","If xv's value is nil because the variable is unreadable, rebuild with `-gcflags='all=-N -l'` or move the breakpoint to where the variable is live.","Ensure the right operand is an integer kind too (uint or int types) per the subsequent checks in negotiateType."],"exampleFix":"// before (f is a float)\n(dlv) print f << 2\nshift of type float64\n\n// after\n(dlv) print int(f) << 2 // explicit conversion\n(dlv) print i << 2 // or shift the integer variable directly","handlingStrategy":"validation","validationCode":"// Ensure both shift operands are integers:\n(dlv) print x        // must be an int kind\n(dlv) print int(f) << 2  // convert floats explicitly\n// In program code: if x != 0 { y := x << n }","typeGuard":"func isInteger(v interface{}) bool {\n    k := reflect.TypeOf(v).Kind()\n    return k >= reflect.Int && k <= reflect.Uintptr\n}","tryCatchPattern":null,"preventionTips":["Apply shifts only to integer operands.","Convert floats/uints explicitly before shifting.","If the left operand prints as unreadable, rebuild with optimization disabled."],"tags":["debugger","expression-evaluation","shift-operator","type-mismatch"],"backgroundTag":"invalid-shift-operand","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}