go-delve/delve · error

can not assign value of type %T to %T.%q

Error message

can not assign value of type %T to %T.%q

What it means

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.

Source

Thrown at pkg/terminal/starbind/conv.go:220

	r := v.v.FieldByName(name)
	if !r.IsValid() {
		return starlark.NoSuchAttrError(fmt.Sprintf("no field named %q in %T", name, v.v.Interface()))
	}
	switch value := value.(type) {
	case starlark.Int:
		n, ok := value.Int64()
		if !ok {
			return fmt.Errorf("can not assign big integer to %T.%q", v.v.Interface(), name)
		}
		r.SetInt(n)
	case starlark.Float:
		r.SetFloat(float64(value))
	case starlark.String:
		r.SetString(value.GoString())
	case starlark.Bool:
		r.SetBool(bool(value))
	default:
		return fmt.Errorf("can not assign value of type %T to %T.%q", value, v.v.Interface(), name)
	}
	return nil
}

func (v structAsStarlarkValue) valueAttr(name string) (starlark.Value, error) {
	if v.v.Type().Name() != "Variable" || (name != "Value" && name != "Expr") {
		return nil, nil
	}
	v2 := v.v.Interface().(api.Variable)

	if name == "Expr" {
		return starlark.String(varAddrExpr(&v2)), nil
	}

	return v.env.variableValueToStarlarkValue(&v2, true)
}

func varAddrExpr(v *api.Variable) string {

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Match the value type to the field type: int/float/string/bool only
  2. Build the Go-side value through a dedicated API function instead of direct assignment
  3. Inspect the wrapped Go struct type (printed in the error) to see the expected field type

Example fix

# before
conf.MaxStringLen = [512, 1024]   # list into int field
# after
conf.MaxStringLen = 1024          # scalar assignment
Defensive patterns

Strategy: type-guard

Validate before calling

TYPES = {int, float, str, bool}
assert type(value) in TYPES, "unsupported Starlark type for scalar field: %s" % type(value)

Type guard

def is_scalar_starlark(v):
    return isinstance(v, (int, float, str, bool))

Try / catch

try:
    obj.field = value
except Exception as e:
    if "can not assign value of type" in str(e):
        obj.field = coerce_to_field_type(value, obj, "field")
    else:
        raise

Prevention

When it happens

Trigger: `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.

Common situations: 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).

Related errors


AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31). Data as JSON: /api/errors/643c490c52b0f376. Report an issue: GitHub.