golang/go

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

Closed

#75.422 geöffnet am 11. Sept. 2025

Auf GitHub ansehen
 (5 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Go (19.008 Forks)batch import
AnalysisFeatureRequestToolsgoplshelp wanted

Repository-Metriken

Stars
 (133.883 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

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".

Contributor Guide