Skip to content

x/tools/gopls/internal/analysis/modernize: add pass to use reflect.TypeAssert #75422

@adonovan

Description

@adonovan

https://go.dev/cl/702735 replaced v.Interface().(T) with reflect.TypeAssert[T](v), where v is a reflect.Value, and demonstrated a significant performance improvement. Although the new code is 7 chars longer, it is more direct and arguably clearer. We should add a modernizer to automate this transformation when v.Interface().(T) appears in a two-value (x, ok := ...) context in a file using go1.25 or later. The doc comment for TypeAssert states that they are "semantically equivalent".

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)FeatureRequestIssues asking for a new feature that does not need a proposal.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.help wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions