Skip to content

[stdlib] Fix FileHandle.seek offset type from UInt64 to Int64#6387

Open
isaacuselman wants to merge 1 commit intomodular:mainfrom
isaacuselman:fix-seek-int64
Open

[stdlib] Fix FileHandle.seek offset type from UInt64 to Int64#6387
isaacuselman wants to merge 1 commit intomodular:mainfrom
isaacuselman:fix-seek-int64

Conversation

@isaacuselman
Copy link
Copy Markdown
Contributor

@isaacuselman isaacuselman commented Apr 8, 2026

Fixes #4473

Summary

  • Changes FileHandle.seek offset parameter from UInt64 to Int64 to match lseek semantics — negative offsets are valid with SEEK_CUR and SEEK_END
  • Applies the same fix to NamedTemporaryFile.seek which wraps FileHandle.seek
  • Updates test_print.mojo to use Int64 for the seek cursor (downstream consumer of the API change)
  • Adds test_file_seek_int64_offset unit test covering positive, negative, and relative negative offsets

Testing

  • //mojo/stdlib/test/builtin:test_file.mojo.test — passes (includes new Int64 offset test)
  • //mojo/stdlib/test/tempfile:test_tempfile.mojo.test — passes
  • //mojo/stdlib/test/builtin:test_print.mojo.test — passes (updated cursor type)

Checklist

  • PR is small and focused — consider splitting larger changes into a sequence of smaller PRs
  • I ran ./bazelw run format to format my changes
  • I added or updated tests to cover my changes
  • If AI tools assisted with this contribution, I have included an Assisted-by: trailer in my commit message or this PR description (see AI Tool Use Policy)

@isaacuselman isaacuselman requested a review from a team as a code owner April 8, 2026 21:53
@github-actions github-actions Bot added mojo-stdlib Tag for issues related to standard library waiting-on-review labels Apr 8, 2026
Copy link
Copy Markdown
Member

@JoeLoser JoeLoser left a comment

Choose a reason for hiding this comment

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

Do you mind adding some unit tests, please?

@isaacuselman isaacuselman force-pushed the fix-seek-int64 branch 3 times, most recently from 8e48cde to 96ca7b1 Compare April 8, 2026 22:49
@isaacuselman
Copy link
Copy Markdown
Contributor Author

Added test_file_seek_int64_offset — tests positive, negative (SEEK_END), and relative negative (SEEK_CUR) Int64 offsets.

The `seek` method accepts `UInt64` for the offset parameter, but `lseek`
takes a signed `off_t` and negative offsets are valid with SEEK_CUR and
SEEK_END. The internal implementation already casts to Int64. This fixes
the public API to match the actual semantics.

Also fixes NamedTemporaryFile.seek which wraps FileHandle.seek.

Fixes modular#4473

Assisted-by: Claude (Anthropic)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

:wq# You are currently rebasing branch 'fix-seek-int64' on '43e38e8'.
:wq#
~
~
~      #
@ConnorGray
Copy link
Copy Markdown
Member

!sync

@modularbot modularbot added the imported-internally Signals that a given pull request has been imported internally. label Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

imported-internally Signals that a given pull request has been imported internally. mojo-stdlib Tag for issues related to standard library waiting-on-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] FileHandle.seek takes negative values in the docs despite being of type uint64

4 participants