go-delve/delve · error

could not evaluate function or type %s: %v

Error message

could not evaluate function or type %s: %v

What it means

When compiling a type cast or function call, Delve attempts to resolve node.Fun as a type; if the type lookup fails with reader.ErrTypeNotFound and there was an earlier ambiguity (ambiguousErr), it reports 'could not evaluate function or type <expr>: <ambiguous error>'. This surfaces when the name is ambiguous between a function and a type, or the DWARF type reader cannot uniquely resolve the referenced type.

Source

Thrown at pkg/proc/evalop/evalcompile.go:584

		return err
	}

	fnnode := node.Fun

	// remove all enclosing parenthesis from the type name
	fnnode = removeParen(fnnode)

	targetTypeStr := astutil.ExprToString(removeParen(node.Fun))
	styp, err := ctx.FindTypeExpr(fnnode)
	if err != nil {
		switch targetTypeStr {
		case "[]byte", "[]uint8":
			styp = godwarf.FakeSliceType(godwarf.FakeBasicType("uint", 8))
		case "[]int32", "[]rune":
			styp = godwarf.FakeSliceType(godwarf.FakeBasicType("int", 32))
		default:
			if ambiguousErr != nil && err == reader.ErrTypeNotFound {
				return fmt.Errorf("could not evaluate function or type %s: %v", astutil.ExprToString(node.Fun), ambiguousErr)
			}
			return err
		}
	}

	ctx.pushOp(&TypeCast{DwarfType: styp, Node: node})
	return nil
}

func (ctx *compileCtx) compileBuiltinCall(builtin string, args []ast.Expr) error {
	for _, arg := range args {
		err := ctx.compileAST(arg, false)
		if err != nil {
			return err
		}
	}
	ctx.pushOp(&BuiltinCall{builtin, args})
	return nil

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Fully qualify the type/function with its package path in the expression
  2. Rebuild the binary with complete DWARF (avoid -w/-s, avoid stripping); for cgo ensure debug info is generated
  3. If a name is ambiguous, rename the cast target or disambiguate with a temporary variable of the desired type
  4. Upgrade delve — generic/parametric type resolution improves across versions

Example fix

// before
(dlv) print T(v)
// after
(dlv) print (*main.T)(v) // or fully qualified: mypkg.T(v)
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

_, err := eval("mypkg.T(x)")
if err != nil && strings.Contains(err.Error(), "could not evaluate function or type") {
	// retry with fully-qualified type name or check binary DWARF completeness
}

Prevention

When it happens

Trigger: A cast expression like 'mypkg.T(x)' where T's DWARF type cannot be found (ErrTypeNotFound) while a prior lookup attempt recorded an ambiguity; calling a name that could be either a function or a parametric/generic type; types from Cgo or incomplete DWARF.

Common situations: Debugging generics-heavy code where instantiated type names are hard to resolve; stripped or partial DWARF (e.g. from cgo or external linkers); name collisions between a function and a type in different packages.

Related errors


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