Skip to content

Send fmt.Fprintln to the writer it is given - #216

Merged
tylerlaprade merged 2 commits into
masterfrom
claude/fprintln-writers
Nov 24, 2026
Merged

tylerlaprade merged 2 commits into
masterfrom
claude/fprintln-writers

Conversation

@tylerlaprade

@tylerlaprade tylerlaprade commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Fixes DEV-161.

fmt.Fprintln(w, ...) printed to stdout for every w except a strings.Builder and os.Stderr:

l := &Lines{}            // has its own Write method
fmt.Fprintln(l, "a", 1)  // Go: l gets "a 1\n"   Rust: "a 1" on the terminal, l gets nothing

A type with its own Write, a bytes.Buffer, a bufio.Writer and an io.Writer parameter all lost the line. Fprint and Fprintf already wrote to these writers. Fprintln now takes the same paths, and returns the same (int, error).

Two more bugs, found in the same probe:

Go Before Now
fmt.Fprintln(w, args...), fmt.Fprint(w, args...) with args []any printed the slice as one value prints its elements, as Println(args...) does
[]any{l.prefix} in a method of l boxed the field's cell; printing it panicked: "cannot print this value held in an interface" boxes the field's value

Fixtures:

  • fprintln_writers: a type with its own Write, a bytes.Buffer, a bufio.Writer, an io.Writer parameter, and os.Stdout.
  • fprintln_writers_plain: a program that needs no shared-state wrappers. It covers a writer, Fprintln's (int, error), a logger whose value receiver spreads []any{prefix, args...}, and Fprint(w, args...).

Both match Go. No other snapshot changes. The ratchet is unchanged.

Not covered: writing to a file from os.Create does not compile at all on master. That is DEV-150, in the next PR.

— agent: claude-chat


Generated by Claude Code

Summary by Sourcery

Route fmt.Fprintln consistently to its supplied writer and align variadic interface formatting with Go behavior.

Bug Fixes:

  • Make fmt.Fprintln write to supported destination writers, including user-defined writers, buffers, buffered writers, and io.Writer values, while preserving its return values.
  • Correct variadic Fprint and Fprintln calls with []any arguments to print individual elements.
  • Ensure receiver fields placed in []any are boxed as their values rather than internal field cells.

Tests:

  • Add transpiler regression tests and end-to-end fixtures covering writer routing, variadic formatting, return values, and receiver-field boxing.

fmt.Fprintln(w, ...) printed to stdout for every w but a strings.Builder
and os.Stderr: a type with its own Write, a bytes.Buffer, a bufio.Writer
and an io.Writer parameter all lost the line, and it showed on the
terminal instead. Fprint and Fprintf already wrote to these writers.
Fprintln now takes the same paths.

Also:

- Fprintln(w, args...) and Fprint(w, args...) with args a []any printed
  the slice as one value. They now print its elements, as Println(args...)
  does.
- A field of the method's receiver in a []any literal, []any{l.prefix},
  was boxed as the field's cell, and printing it panicked ("cannot print
  this value held in an interface"). It is boxed as its value.

Fixtures: fprintln_writers covers a type with its own Write, a
bytes.Buffer, a bufio.Writer, an io.Writer parameter and os.Stdout;
fprintln_writers_plain covers a writer, Fprintln's (int, error), a
logger whose value receiver spreads []any{prefix, args...}, and
Fprint(w, args...). Both match Go. No other snapshot changes. The ratchet
is unchanged.

Agent: claude-chat
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TkCXVghVg3khqYkpQSWyEM
@tylerlaprade tylerlaprade added the agent:claude-chat Work by the Claude chat agent (claude.ai session), acting as the repo owner label Nov 24, 2026 — with Claude
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-24T11:28:00.581706Z
We couldn’t complete this review. Comment @codex review to try again.
f2534eb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 628eddbc-78f5-4ab3-b4d7-3536b15f6f86
Commits

Reviewing files that changed from the base of the PR and between 17ed6d8 and 6e9fe76.

Files selected for processing: 12

  • go/expr.go
  • go/fprintln_writers_test.go
  • go/stdlib.go
  • tests.bats
  • tests/fprintln_writers/Cargo.toml
  • tests/fprintln_writers/expected_output.txt
  • tests/fprintln_writers/main.go
  • tests/fprintln_writers/main.rs
  • tests/fprintln_writers_plain/Cargo.toml
  • tests/fprintln_writers_plain/expected_output.txt
  • tests/fprintln_writers_plain/main.go
  • tests/fprintln_writers_plain/main.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sourcery-ai

sourcery-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Sorry @tylerlaprade, this account has used its review budget of 1,500,000 diff characters for the last 7 days.

You can request another review in 1 day and 13 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@tylerlaprade
tylerlaprade merged commit d6fac23 into master Nov 24, 2026
0 of 2 checks passed
@tylerlaprade
tylerlaprade deleted the claude/fprintln-writers branch November 24, 2026 12:45
@sourcery-ai

sourcery-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Route Fprintln through the writer paths used by Fprint and Fprintf, and format spread []any arguments as individual operands.

  • go/stdlib.go L1712-1733, L1778-1792, L1852-1856

Detect receiver field selectors and box their owned value rather than the field cell when building interface slices.

  • go/expr.go L7968-7986, L15748-15750

Tests

Add focused transpiler regressions for writer-directed Fprintln, spread arguments, and receiver-field boxing.

  • go/fprintln_writers_test.go L1-80

Add end-to-end fixtures covering custom and standard writers, return values, interface-slice spreads, and expected output.

  • tests.bats L1426-1433
  • tests/fprintln_writers/Cargo.toml L1-39
  • tests/fprintln_writers/expected_output.txt L1-5
  • tests/fprintln_writers/main.go L1-46
  • tests/fprintln_writers/main.rs L1-923
  • tests/fprintln_writers_plain/Cargo.toml L1-11
  • tests/fprintln_writers_plain/expected_output.txt L1-7
  • tests/fprintln_writers_plain/main.go L1-49
  • tests/fprintln_writers_plain/main.rs L1-1578

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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

Labels

agent:claude-chat Work by the Claude chat agent (claude.ai session), acting as the repo owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants