go-delve/delve · error
shift of type %s
Error message
shift of type %s
What it means
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.
Source
Thrown at pkg/proc/eval.go:2438
r.Value = rc
stack.push(r)
return
}
stack.push(newConstant(rc, xv.bi, xv.mem))
}
func negotiateType(op token.Token, xv, yv *Variable) (godwarf.Type, error) {
if xv == nilVariable {
return nil, negotiateTypeNil(op, yv)
}
if yv == nilVariable {
return nil, negotiateTypeNil(op, xv)
}
if op == token.SHR || op == token.SHL {
if xv.Value == nil || xv.Value.Kind() != constant.Int {
return nil, fmt.Errorf("shift of type %s", xv.Kind)
}
switch yv.Kind {
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
// ok
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
if constant.Sign(yv.Value) < 0 {
return nil, errors.New("shift count must not be negative")
}
default:
return nil, fmt.Errorf("shift count type %s, must be unsigned integer", yv.Kind.String())
}
return xv.DwarfType, nil
}
if xv.DwarfType == nil && yv.DwarfType == nil {
return nil, nilView on GitHub (pinned to a23773e6c3)
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.
Example fix
// before (f is a float) (dlv) print f << 2 shift of type float64 // after (dlv) print int(f) << 2 // explicit conversion (dlv) print i << 2 // or shift the integer variable directly
Defensive patterns
Strategy: validation
Validate before calling
// Ensure both shift operands are integers:
(dlv) print x // must be an int kind
(dlv) print int(f) << 2 // convert floats explicitly
// In program code: if x != 0 { y := x << n } Type guard
func isInteger(v interface{}) bool {
k := reflect.TypeOf(v).Kind()
return k >= reflect.Int && k <= reflect.Uintptr
} Prevention
- Apply shifts only to integer operands.
- Convert floats/uints explicitly before shifting.
- If the left operand prints as unreadable, rebuild with optimization disabled.
When it happens
Trigger: 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.)
Common situations: 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.
Related errors
- shift count must not be negative
- invalid argument 1 %s (type %s) to complex
- invalid argument 2 %s (type %s) to complex
- invalid argument %s (type %s) to imag
- invalid argument %s (type %s) to real
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/872e30627f9bb23f.
Report an issue: GitHub.