Severity: medium
Summary
When the argument to on.Click (or any on.*) isn't a bound method value, the panic text is
on: click requires a bound method value (e.g. on.Click(c.Inc)); got a closure, top-level function, or nil
The framework already has the reflect.Value of the failing argument and can distinguish closure / top-level / nil.
Where
on/on.go:161
on/on.go:232
Why it matters
UX nit, but this is the most common authoring mistake for the on package and the message is one of the most-read. Telling the dev exactly which of the three they did wrong saves a round of squinting.
Suggested fix
Switch on the value's kind / nil-ness and emit the specific case:
case fn == nil: → "got nil"
case top-level function: → "got a top-level function — Via needs a method bound to a composition instance"
default (closure): → "got a closure — Via needs a method directly, not wrapped"
runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name() exposes the underlying function name and lets you detect closures by the .func1 suffix convention.
Severity: medium
Summary
When the argument to
on.Click(or anyon.*) isn't a bound method value, the panic text isThe framework already has the
reflect.Valueof the failing argument and can distinguish closure / top-level / nil.Where
on/on.go:161on/on.go:232Why it matters
UX nit, but this is the most common authoring mistake for the
onpackage and the message is one of the most-read. Telling the dev exactly which of the three they did wrong saves a round of squinting.Suggested fix
Switch on the value's kind / nil-ness and emit the specific case:
runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()exposes the underlying function name and lets you detect closures by the.func1suffix convention.