go-delve/delve · error
allocating a literal of type %s not implemented
Error message
allocating a literal of type %s not implemented
What it means
maybeMaterialize allocates real storage in the debuggee for literal values produced by compiled expressions (so they can be assigned or passed by reference). The default case — MapType, SliceType, or FuncType literals — is not implemented, so it errors with 'allocating a literal of type %s not implemented'. Assignment (set) or call arguments whose literal has one of these types cannot be materialized.
Source
Thrown at pkg/proc/evalop/evalcompile.go:882
ctx.pushOp(&TypeCast{
DwarfType: godwarf.FakePointerType(dtyp, int64(ctx.PtrSize())),
Node: &ast.CallExpr{
Fun: lit.Type,
Args: []ast.Expr{&ast.Ident{Name: "new allocation"}}}})
xderef := &ast.StarExpr{X: &ast.Ident{Name: "new-allocation"}}
xset := &ast.Ident{Name: "literal-allocation"}
ctx.pushOp(&Dup{}) // stack after: [ ptrToRealLiteral, ptrToRealLiteral, fakeLiteral ]
ctx.pushOp(&PointerDeref{xderef}) // stack after: [ realLiteral, ptrToRealLiteral, fakeLiteral ]
ctx.pushOp(&Roll{2}) // stack after: [ fakeLiteral, realLiteral, ptrToRealLiteral ]
ctx.pushOp(&Roll{1}) // stack after: [ realLiteral, fakeLiteral, ptrToRealLiteral ]
ctx.pushOp(&SetValue{Rhe: xset}) // stack after: [ ptrToRealLiteral ]
return nil
default:
// either *godwarf.MapType, *godwarf.SliceType or *godwarf.FuncType
return fmt.Errorf("allocating a literal of type %s not implemented", dtyp.String())
}
}
func Listing(depth []int, ops []Op) string {
if depth == nil {
depth = make([]int, len(ops)+1)
}
buf := new(strings.Builder)
for i, op := range ops {
fmt.Fprintf(buf, " %3d (%2d->%2d) %#v\n", i, depth[i], depth[i+1], op)
}
return buf.String()
}
func isStringLiteralThatNeedsAlloc(expr ast.Expr) bool {
switch expr := expr.(type) {
case *ast.BasicLit:View on GitHub (pinned to a23773e6c3)
Solutions
- Mutate in place instead of assigning a new literal: 'set m["k"] = v' or 'set s[0] = x'
- Populate via a program function using call injection: define/look for a constructor in the debuggee and 'call makeMap(...)',' or write the assignment in the source code and re-run
- Avoid reassigning function values; set them in source and restart the debug session
Example fix
// before
(dlv) set m = map[string]int{"a": 1}
// after
(dlv) set m["a"] = 1 // mutate existing map Defensive patterns
Strategy: fallback
Validate before calling
// Detect literal assignment to map/slice/func types and fall back to mutation
if strings.Contains(expr, "=") && (strings.Contains(expr, "map[") || strings.Contains(expr, "[]") || strings.Contains(expr, "func")) {
// plan element-wise mutation instead of whole-literal assignment
} Type guard
null
Try / catch
null
Prevention
- Mutate maps/slices element-wise instead of assigning new literals
- Add a constructor function in the program and use call
- Reassign such values in source and re-run
When it happens
Trigger: 'set m = map[string]int{...}' or passing a map/slice/func literal as a call argument; any path where CompileSet, compileAST, or a function-call compile needs to materialize a map/slice/func-typed literal.
Common situations: Trying to assign a whole new map or slice literal to a variable at the (dlv) prompt; attempting 'set f = someFunc' style reassignment of function values; IDE set-value actions on composite literals.
Related errors
- shift count must not be negative
- invalid argument %s (type %s) for cap
- wrong number of arguments to len: %d
- invalid argument %s (type %s) for len
- wrong number of arguments to complex: %d
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/fc34fb40c687396f.
Report an issue: GitHub.