{"record":{"id":"643c490c52b0f376","repo":"go-delve/delve","slug":"can-not-assign-value-of-type-t-to-t-q","errorCode":null,"errorMessage":"can not assign value of type %T to %T.%q","messagePattern":"can not assign value of type %T to %T\\.%q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/terminal/starbind/conv.go","lineNumber":220,"sourceCode":"\tr := v.v.FieldByName(name)\n\tif !r.IsValid() {\n\t\treturn starlark.NoSuchAttrError(fmt.Sprintf(\"no field named %q in %T\", name, v.v.Interface()))\n\t}\n\tswitch value := value.(type) {\n\tcase starlark.Int:\n\t\tn, ok := value.Int64()\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"can not assign big integer to %T.%q\", v.v.Interface(), name)\n\t\t}\n\t\tr.SetInt(n)\n\tcase starlark.Float:\n\t\tr.SetFloat(float64(value))\n\tcase starlark.String:\n\t\tr.SetString(value.GoString())\n\tcase starlark.Bool:\n\t\tr.SetBool(bool(value))\n\tdefault:\n\t\treturn fmt.Errorf(\"can not assign value of type %T to %T.%q\", value, v.v.Interface(), name)\n\t}\n\treturn nil\n}\n\nfunc (v structAsStarlarkValue) valueAttr(name string) (starlark.Value, error) {\n\tif v.v.Type().Name() != \"Variable\" || (name != \"Value\" && name != \"Expr\") {\n\t\treturn nil, nil\n\t}\n\tv2 := v.v.Interface().(api.Variable)\n\n\tif name == \"Expr\" {\n\t\treturn starlark.String(varAddrExpr(&v2)), nil\n\t}\n\n\treturn v.env.variableValueToStarlarkValue(&v2, true)\n}\n\nfunc varAddrExpr(v *api.Variable) string {","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/terminal/starbind/conv.go#L202-L238","documentation":"SetField's default branch: the Starlark value's type has no conversion to the Go field's kind. Only starlark.Int, Float, String and Bool are handled; assigning None (handled earlier), lists, dicts, tuples, functions or other Starlark values to a scalar Go struct field produces this typed error naming both types.","triggerScenarios":"`obj.field = [1,2,3]`, `obj.field = {\"a\":1}`, or `obj.field = some_function` where field is an int/string/bool Go field in a struct exposed to Starlark.","commonSituations":"Scripts copying a whole dict into a config field, or expecting Delve to auto-convert lists/dicts into Go slices/maps (it does not in SetField).","solutions":["Match the value type to the field type: int/float/string/bool only","Build the Go-side value through a dedicated API function instead of direct assignment","Inspect the wrapped Go struct type (printed in the error) to see the expected field type"],"exampleFix":"# before\nconf.MaxStringLen = [512, 1024]   # list into int field\n# after\nconf.MaxStringLen = 1024          # scalar assignment","handlingStrategy":"type-guard","validationCode":"TYPES = {int, float, str, bool}\nassert type(value) in TYPES, \"unsupported Starlark type for scalar field: %s\" % type(value)","typeGuard":"def is_scalar_starlark(v):\n    return isinstance(v, (int, float, str, bool))","tryCatchPattern":"try:\n    obj.field = value\nexcept Exception as e:\n    if \"can not assign value of type\" in str(e):\n        obj.field = coerce_to_field_type(value, obj, \"field\")\n    else:\n        raise","preventionTips":["Assign only scalars to struct fields from Starlark","Construct complex values (lists/dicts/structs) via dedicated API calls","Check the wrapped Go type printed in the error"],"tags":["starlark","delve","scripting","type-mismatch"],"backgroundTag":"starlark-type-mismatch","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}