Skip to content

U1000: A false positive when using generic interfaces #1440

Closed

Description

@adamroyjones

This is with staticcheck 2023.1.5 (v0.4.5) and Go 1.21.0.

Here's a very contrived main.go file.

// main.go
package main

import (
	"errors"
	"fmt"
)

func main() {
	f(s{})
}

func f(ii i[error]) {
	fmt.Printf("%v\n", ii.m())
}

type i[T any] interface {
	m() T
}

type s struct{}

func (ss s) m() error {
	return errors.New("from s")
}

This runs happily and prints out "from s". However:

$ staticcheck ./...
main.go:22:13: func s.m is unused (U1000)

If this becomes

// main.go
package main

import (
	"errors"
	"fmt"
)

func main() {
	f(s{})
}

func f(ii i) {
	fmt.Printf("%v\n", ii.m())
}

type i interface {
	m() error
}

type s struct{}

func (ss s) m() error {
	return errors.New("from s")
}

then all is well.

Do you have any thoughts around this? I appreciate that it seems like a goofy example, but it's a reduced version of something a little less goofy.

Activity

  1. added
    needs-triage
    on Aug 24, 2023
  2. removed
    needs-triage
    on Aug 24, 2023
  3. dominikh commented on Aug 24, 2023

    @dominikh
    Owner

    Do you have any thoughts around this?

    Looks like a bug that we should fix.

  4. all2ham commented on Jul 4, 2024

    @all2ham

    whats the latest on this

  5. ajscholl commented on Dec 3, 2025

    @ajscholl

    I think I also ran into this today, for me this program triggered the bug:

    package main
    
    import "fmt"
    
    func main() {
    	run(myStruct{})
    }
    
    func run[E any, T myInterface[E]](repo T) {
    	repo.notUnused(nil)
    }
    
    type myStruct struct{}
    
    func (myStruct) notUnused(_ []any) {
    	fmt.Println("Not unused called")
    }
    
    type myInterface[E any] interface {
    	notUnused(events []E)
    }
    
    // uncommenting removes the lint
    // var _ myInterface[any] = myStruct{}
  6. added 3 commits that reference this issue on Jun 7, 2026
    f34af32
    d623b60
    875903a
  7. added a commit that references this issue on Jun 23, 2026
    f0503f7
  8. added a commit that references this issue on Jun 25, 2026
    9fce5f8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions