crawshaw / sqlite

Go SQLite3 driver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Blob struct should not have io interfaces as fields

infogulch opened this issue · comments

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{}