Skip to content

bug: (go1.27) unusedmethod analyzer false positive with generic methods #56

@ldez

Description

@ldez

go1.27 will introduce generic methods.

unusedmethod analyzer is not working as expected with those new elements.

main.go
package main

func main() {
	var g G[string]
	var _ I = g

	g.m("foo")

	var h H
	h.m[string]("foo")
}

type G[P any] struct{}

func (G[P]) m(P) {}

type I interface {
	m(string)
}

type H struct{}

func (H) m[P any](P) {}
Details
version: 2

linters:
  default: none
  enable:
    - iface
  settings:
    iface:
      enable:
        - unusedmethod
$ ./golangci-lint run
main.go:18:2: unusedmethod: method 'm()' is declared on interface 'I' but not used within the package (iface)
        m(string)
        ^
1 issues:
* iface: 1

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