Skip to content

Blob struct should not have io interfaces as fields #147

Description

@infogulch

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions