Skip to content

QF1011, ST1023: the type isn't redundant for uninstantiated generic rhs #1673

Open

Description

@dominikh
No description provided.

Activity

  1. far4599 commented on Sep 24, 2026

    @far4599

    The same false positive happens with a method value of a generic method (Go 1.27),
    where the suggested fix does not compile either:

    // Package st1023 reproduces a false positive.
    package st1023
    
    type T struct{}
    
    func (T) M[P any](v P) P { return v }
    
    func F(t T) string {
    	var f func(string) string = t.M
    	return f("a")
    }
    $ staticcheck -checks ST1023 ./...
    st.go:9:8: should omit type func(string) string from declaration; it will be inferred from the right-hand side (ST1023)
    

    After applying the suggestion (var f = t.M):

    $ go build ./...
    ./st.go:9:10: cannot use generic function t.M without instantiation
    

    staticcheck 2026.2.1 (0.8.1), go1.27.0 darwin/arm64.

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