Skip to content

fix(mutable): move Fill to slice.go to export it properly - #1053

Open
mazkev wants to merge 1 commit into
samber:masterfrom
mazkev:fix/mutable-fill-export
Open

mazkev wants to merge 1 commit into
samber:masterfrom
mazkev:fix/mutable-fill-export

Conversation

@mazkev

@mazkev mazkev commented Oct 27, 2026

Copy link
Copy Markdown

Describe your changes

In the mutable package, func Fill was accidentally declared inside mutable/slice_example_test.go instead of mutable/slice.go.

Because Go omits _test.go files during compilation for external consumers, mutable.Fill was not actually exported in the public API when importing github.com/samber/lo/mutable (undefined: mutable.Fill).

Changes made:

  1. Move func Fill: Moved from mutable/slice_example_test.go to mutable/slice.go.
  2. Add ExampleFill: Added a runnable ExampleFill() in mutable/slice_example_test.go to verify the example and keep documentation examples complete.
  3. Update Documentation:
    • Updated sourceRef in docs/data/mutable-fill.md to point to mutable/slice.go#L78.
    • Fixed example snippet in docs/data/mutable-fill.md to use lom.Fill instead of lo.Fill.

Verification:

  • go doc ./mutable now correctly lists:
    func Fill[T any, Slice ~[]T](collection Slice, initial T)

Fill was accidentally defined in slice_example_test.go instead of slice.go, causing it to not be exported as part of the public mutable package.

This moves func Fill into slice.go, adds ExampleFill() in slice_example_test.go, and updates the source reference and example in docs/data/mutable-fill.md.

@rahul05ranjan rahul05ranjan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified the bug and the fix — this was a real export failure, not just a misplaced definition. Since Fill was declared inside slice_example_test.go, it only existed in the test build of the package: any consumer importing github.com/samber/lo/mutable got undefined: mutable.Fill, while the package's own examples kept passing because they live in the same test package. Your description matches exactly how Go handles _test.go files.

Details I checked:

  • The new location lines up with the docs metadata: sourceRef: mutable/slice.go#L78 matches the convention used by the neighboring entries (mutable-reverse.md points at slice.go#L66, which is precisely its func Reverse line, and func Fill lands on line 78 after the move).
  • The doc example now follows the mutable-package convention — import lom "github.com/samber/lo/mutable" + lom.Fill(...), same style as the Reverse docs. The old doc block showing lo.Fill was doubly wrong since that helper lives in lo root as the immutable Fill and this one never existed as mutable.Fill for consumers.
  • Turning the stray generic function into a proper func ExampleFill() with an // Output: block means it's now both compiled in go test and rendered in godoc, which the previous construction (an unexported-looking generic func in an example file, which godoc would have ignored) never achieved.

One thing you might double-check: since Fill was invisible to consumers until now, this is effectively a new symbol in the public mutable API — worth a line in the release notes if the project tracks those per-helper (the changelog-generation setup will probably pick it up automatically from the move, but worth confirming it lands under "added" rather than being silent).

@mazkev

mazkev commented Oct 30, 2026

Copy link
Copy Markdown
Author

Thanks a lot for the thorough review and verification, @rahul05ranjan!

Good point regarding the release notes / changelog — since mutable.Fill was previously unreachable outside package tests, classifying it as a newly exported symbol in the mutable API makes total sense. I'll defer to @samber on the preferred changelog tag (or whether the release automation handles it from the commit), and happy to tweak the PR title/commit message if needed.

This branch has not been deployed

No deployments
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.

2 participants