Skip to content

Commit

Permalink
interp: let HandlerContext.Stdin be nil again when there is no stdin
Browse files Browse the repository at this point in the history
We recently changed Runner.stdin from an io.Reader to an *os.File.
One unintended consequence of this change is that HandlerContext.Stdin
is filled directly from that value, so when the file was nil,
we would now fill Stdin with a typed nil, which is not nil.

This new behavior was unintentional and entirely confusing. Avoid it,
and add a comment to ensure we don't fall into that again.
  • Loading branch information
mvdan committed Oct 20, 2024
1 parent 7a3cb55 commit 686e8c1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion interp/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,12 @@ func (r *Runner) handlerCtx(ctx context.Context) context.Context {
hc := HandlerContext{
Env: &overlayEnviron{parent: r.writeEnv},
Dir: r.Dir,
Stdin: r.stdin,
Stdout: r.stdout,
Stderr: r.stderr,
}
if r.stdin != nil { // do not leave hc.Stdin as a typed nil
hc.Stdin = r.stdin
}
return context.WithValue(ctx, handlerCtxKey{}, hc)
}

Expand Down

0 comments on commit 686e8c1

Please sign in to comment.