golang/go

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

Open

#75.422 aperta il 11 set 2025

Vedi su GitHub
 (5 commenti) (0 reazioni) (0 assegnatari)Go (19.008 fork)batch import
AnalysisFeatureRequestToolsgoplshelp wanted

Metriche repository

Star
 (133.883 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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

Guida contributor