Skip to content

fix(compiler): await interface calls in a literal passed to ServeMux.HandleFunc - #216

Merged
paralin merged 1 commit into
masterfrom
fix/servemux-handlefunc
Oct 7, 2026
Merged

paralin merged 1 commit into
masterfrom
fix/servemux-handlefunc

Conversation

@paralin

@paralin paralin commented Oct 7, 2026

Copy link
Copy Markdown
Member

A handler literal passed to ServeMux.HandleFunc or http.HandleFunc lowered with async calls disallowed, because HandleFunc is synchronous and takes an unnamed func type. Interface calls such as w.Header() and w.Write stayed unawaited and failed the type check, or were awaited only when another file in the program made WriteHeader async. Override metadata gains an optional asyncCallbacks key naming the callback parameters the runtime stores and awaits; the net/http override names the handler of both HandleFunc forms, and lowerFixedCallArgs allows async calls in such a literal. The new net_http_servemux_handlefunc fixture registers handlers that call w.Header().Set, w.WriteHeader and w.Write and serves them through httptest.NewRecorder.

…HandleFunc

A function literal passed to an override call lowered with async calls
disallowed unless the callee itself was async. ServeMux.HandleFunc is
synchronous and takes an unnamed func type, so the async metadata of
HandlerFunc.ServeHTTP never reached its handler literal. Interface calls
such as w.Header() and w.Write stayed unawaited, failing the type check,
or were awaited only when another file in the program made WriteHeader
async.

Override metadata gains asyncCallbacks, which maps a function name or
Type.Method key to the parameters the runtime stores and awaits. The
net/http override names the handler of HandleFunc and ServeMux.HandleFunc.
lowerFixedCallArgs allows async calls in a literal passed for such a
parameter, so every interface call in it awaits. The
net_http_servemux_handlefunc fixture registers handlers that call
w.Header().Set, w.WriteHeader and w.Write and serves them through
httptest.NewRecorder.

Signed-off-by: Christian Stewart <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 7, 2026 23:28
@paralin
paralin merged commit 1a706fc into master Oct 7, 2026
8 checks passed
@paralin
paralin deleted the fix/servemux-handlefunc branch October 7, 2026 23:28
mux.HandleFunc("/mux", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Route", "mux")
w.WriteHeader(http.StatusAccepted)
if _, err := w.Write([]byte("hello " + r.URL.Path)); err != nil {
})
http.HandleFunc("/default", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Route", "default")
if _, err := w.Write([]byte("hello " + r.URL.Path)); err != nil {

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The metadata contract, lowering behavior, runtime implementation, documentation, and regression coverage are consistent.

0 open findings

What changed in this PR

Adds callback-specific async metadata so net/http handler literals correctly await interface calls.

Changes:

  • Adds asyncCallbacks metadata parsing, cloning, lookup, and documentation.
  • Applies callback metadata during fixed argument lowering.
  • Adds compliance coverage for both HandleFunc forms.
File Description
compiler/​lowering.go Enables async lowering for designated callback literals.
compiler/​override-facts.go Loads, queries, and clones callback metadata.
compiler/​override-registry.go Defines callback metadata.
compiler/​override-registry_test.go Tests lookup and immutability.
gs/​net/​http/​meta.json Marks both handler parameters as async-capable.
design/​OVERRIDES.md Documents asyncCallbacks.
tests/​tests/​net_http_servemux_handlefunc/​net_http_servemux_handlefunc.go Adds compliance fixture source.
tests/​tests/​net_http_servemux_handlefunc/​net_http_servemux_handlefunc.gs.ts Checks generated async handlers.
tests/​tests/​net_http_servemux_handlefunc/​expected.log Defines expected runtime output.
tests/​tests/​net_http_servemux_handlefunc/​tsconfig.json Configures fixture type-checking.
tests/​tests/​net_http_servemux_handlefunc/​index.ts Adds the fixture entry module.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants