{"record":{"id":"7bac9c01473d4568","repo":"go-delve/delve","slug":"can-not-assign-to-s","errorCode":null,"errorMessage":"can not assign to %s","messagePattern":"can not assign to (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":658,"sourceCode":"\tcase reflect.Float32, reflect.Float64:\n\t\tf, _ := constant.Float64Val(srcv.Value)\n\t\treturn dstv.writeFloatRaw(f, dstv.RealType.Size())\n\tcase reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:\n\t\tn, _ := constant.Int64Val(srcv.Value)\n\t\treturn dstv.writeUint(uint64(n), dstv.RealType.Size())\n\tcase reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:\n\t\tn, _ := constant.Uint64Val(srcv.Value)\n\t\treturn dstv.writeUint(n, dstv.RealType.Size())\n\tcase reflect.Bool:\n\t\treturn dstv.writeBool(constant.BoolVal(srcv.Value))\n\tcase reflect.Complex64, reflect.Complex128:\n\t\treal, _ := constant.Float64Val(constant.Real(srcv.Value))\n\t\timag, _ := constant.Float64Val(constant.Imag(srcv.Value))\n\t\treturn dstv.writeComplex(real, imag, dstv.RealType.Size())\n\tcase reflect.Func:\n\t\tif dstv.RealType.Size() == 0 {\n\t\t\tif dstv.Name != \"\" {\n\t\t\t\treturn fmt.Errorf(\"can not assign to %s\", dstv.Name)\n\t\t\t}\n\t\t\treturn errors.New(\"can not assign to function expression\")\n\t\t}\n\t}\n\n\t// nilling nillable variables\n\tif srcv == nilVariable {\n\t\treturn dstv.writeZero()\n\t}\n\n\tif srcv.Kind == reflect.String {\n\t\tif srcv.Base == 0 && srcv.Len > 0 && srcv.Flags&VariableConstant != 0 {\n\t\t\treturn errFuncCallNotAllowedStrAlloc\n\t\t}\n\t\treturn dstv.writeString(uint64(srcv.Len), srcv.Base)\n\t}\n\n\t// slice assignment (this is not handled by the writeCopy below so that","sourceCodeStart":640,"sourceCodeEnd":676,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L640-L676","documentation":"setValue cannot assign to a destination of kind Func whose FuncType size is 0: function values in Go are not assignable from the debugger. When the destination variable has a name it is reported via this error; anonymous function destinations get the sibling 'can not assign to function expression' error.","triggerScenarios":"SetVariable(\"someFunc\", ...) or a call-injection argument copy where the target name/expression resolves to a function value (dstv.Kind == reflect.Func with RealType.Size() == 0); e.g. trying to overwrite a function variable, or passing a function-valued destination during fncall argument setup.","commonSituations":"Attempting `set f = otherFunc` on a func-typed variable; trying to patch a function pointer/callback field; IDE users dragging a function symbol into an assignment; trying to swap implementations at runtime (not supported).","solutions":["Do not assign to function values — the Go debugger cannot rewrite function values; assign an indirect holder instead.","If the goal is indirection, store the target in a func-typed field/variable you control and assign that field's underlying state, or wrap the call: set a bool flag the code checks instead of swapping the func.","If this came from call-injection argument copying, change the injected function signature to not take/return a func argument at that position.","Restrict the UI/automation to disallow assignments whose destination kind is Func before invoking SetVariable."],"exampleFix":"// before\nscope.SetVariable(\"handler\", \"altHandler\") // can not assign to handler\n// after\n// introduce a selectable wrapper instead of assigning the func value\nscope.SetVariable(\"useAltHandler\", \"true\") // code: if useAltHandler { handler = altHandler }","handlingStrategy":"type-guard","validationCode":"dst, err := scope.EvalExpression(name, loadSingleValue)\nif err != nil { return err }\nif dst.Kind == reflect.Func {\n    return fmt.Errorf(\"%s is a function value and cannot be assigned\", name)\n}","typeGuard":"func isAssignableKind(k reflect.Kind) bool {\n    return k != reflect.Func && k != reflect.UnsafePointer\n}","tryCatchPattern":"if err := scope.SetVariable(name, value); err != nil {\n    if strings.HasPrefix(err.Error(), \"can not assign to \") {\n        return fmt.Errorf(\"destination %q is a function value: assignment unsupported\", name)\n    }\n    return err\n}","preventionTips":["Never script assignments whose target names a function symbol","Filter editable targets by Kind before exposing assignment in tooling","Use behavioral indirection (flags, config variables) instead of swapping func values","Check the destination variable's Kind in a prior eval before issuing SetVariable"],"tags":["go","debugger","set-variable","func-kind"],"backgroundTag":"function-value-assignment-unsupported","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}