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

Blob struct should not have io interfaces as fields #147

Open
infogulch opened this issue May 21, 2024 · 1 comment
Open

Blob struct should not have io interfaces as fields #147

infogulch opened this issue May 21, 2024 · 1 comment

Comments

@infogulch
Copy link

infogulch commented May 21, 2024

sqlite/blob.go

Lines 81 to 85 in 6c1d4ad

type Blob struct {
io.ReadWriteSeeker
io.ReaderAt
io.WriterAt
io.Closer

This code defines a struct with fields named ReadWriteSeeker, ReaderAt, WriterAt, and Closer which are never used. Notably, Blob itself implements the functions required by these interfaces. If Blob was an interface this syntax would mean that whatever implements Blob must have the methods in the listed interfaces, but written as a struct this syntax defines four separate fields in the struct itself. This appears to be a mistake.

Here's a playground example that shows this: https://go.dev/play/p/Hr0SlKqYhV9

To require that a struct Blob implements the required interfaces, one can use the "interface guards" pattern like this:

var _ io.ReadWriteSeeker = &Blob{}
var _ io.ReaderAt = &Blob{}
var _ io.WriterAt = &Blob{}
var _ io.Closer = &Blob{}
@anacrolix
Copy link
Contributor

go-llsqlite/crawshaw@236e19b

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

No branches or pull requests

2 participants