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

Comments

Projects
None yet
4 participants
@rsc
Copy link
Contributor

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 Go2 label Nov 15, 2016

@bradfitz

This comment has been minimized.

Copy link
Member

commented Nov 15, 2016

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

Detect io.Seek* being used as the first argument to Seek
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

Detect io.Seek* being used as the first argument to Seek
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

@gopherbot gopherbot added the Proposal label Jun 17, 2017

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jan 23, 2018

@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

This comment has been minimized.

Copy link
Contributor

commented Jun 12, 2018

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

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jan 29, 2019

Closing in favor of #25854.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.