Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: io: SeekStart, SeekCurrent, SeekEnd should have explicit types #17920

Closed
rsc opened this issue Nov 15, 2016 · 4 comments
Closed

proposal: io: SeekStart, SeekCurrent, SeekEnd should have explicit types #17920

rsc opened this issue Nov 15, 2016 · 4 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Proposal v2 A language change or incompatible library change
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Nov 15, 2016

The os package defines

const (
	SEEK_SET int = 0 // seek relative to the origin of the file
	SEEK_CUR int = 1 // seek relative to the current offset
	SEEK_END int = 2 // seek relative to the end
)

For #6885, these were deprecated and recreated in package io. This change does make sense, since io defines the Seeker interface. However, the recreation in package io in golang.org/cl/19862 (acefcb7) is less safe to use than the original in package os, because the explicit int types were dropped:

// Seek whence values.
const (
	SeekStart   = 0 // seek relative to the origin of the file
	SeekCurrent = 1 // seek relative to the current offset
	SeekEnd     = 2 // seek relative to the end
)

This is a mistake and does not compile:

f.Seek(os.SEEK_END, 0)

This is a mistake but DOES compile:

f.Seek(io.SeekEnd, 0)

(It seeks to byte 2 of the file.)

It would be nice if we can fix this at some point by making those constants have type int. Maybe Go 2.

@rsc rsc added this to the Unplanned milestone Nov 15, 2016
@rsc rsc added the v2 A language change or incompatible library change label Nov 15, 2016
@bradfitz
Copy link
Contributor

I'd prefer to delete all these constants for Go 2. io.Seeker is three interfaces in one, with a C interface. I've seen so many fake & lying implementations of Seeker that only implement 1 or sometimes 2 of the methods, and sometimes partially.

dominikh added a commit to dominikh/go-staticcheck that referenced this issue Nov 15, 2016
This detects the issue outlined in
golang/go#17920.

Idea-By: Damian Gryski <damian@gryski.com>
dominikh added a commit to dominikh/go-tools that referenced this issue Jan 24, 2017
This detects the issue outlined in
golang/go#17920.

Idea-By: Damian Gryski <damian@gryski.com>
@rsc rsc changed the title io: SeekStart, SeekCurrent, SeekEnd should have explicit types proposal: io: SeekStart, SeekCurrent, SeekEnd should have explicit types Jun 17, 2017
@ianlancetaylor
Copy link
Contributor

@griesemer and I think that @bradfitz has a good point: if we change things for Go 2, let's consider changing the Seek method to not take a whence argument at all.

@ianlancetaylor ianlancetaylor added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Jan 23, 2018
@ianlancetaylor
Copy link
Contributor

Moved @bradfitz 's suggestion to new issue #25854.

@ianlancetaylor
Copy link
Contributor

Closing in favor of #25854.

@golang golang locked and limited conversation to collaborators Jan 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Proposal v2 A language change or incompatible library change
Projects
None yet
Development

No branches or pull requests

4 participants