You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following example is a bit contrived in order to be as minimal as possible while showing the exceptional case. What appears to be happening is that this check assumes all type assertions will be against concrete types, which works well in the general case but in this generics case we are getting an unhelpful linter message. This code does correctly run the type assertions, counter to what the linter rule suggests.
The output of 'staticcheck -version'
staticcheck 2022.1.3 (v0.3.3)
The output of 'staticcheck -debug.version' (it is fine if this command fails)
staticcheck 2022.1.3 (v0.3.3)
Compiled with Go version: go1.18.2
Main module:
honnef.co/go/tools@v0.3.3 (sum: h1:oDx7VAwstgpYpb3wv0oxiZlxY+foCpRAwY7Vk6XpAgA=)
Dependencies:
github.com/BurntSushi/toml@v0.4.1 (sum: h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=)
golang.org/x/exp/typeparams@v0.0.0-20220218215828-6cf2b201936e (sum: h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM=)
golang.org/x/mod@v0.6.0-dev.0.20220419223038-86c51ed26bb4 (sum: h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=)
golang.org/x/sys@v0.0.0-20211019181941-9d821ace8654 (sum: h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=)
golang.org/x/tools@v0.1.11-0.20220513221640-090b14e8501f (sum: h1:OKYpQQVE3DKSc3r3zHVzq46vq5YH7x8xpR3/k9ixmUg=)
staticcheck (within the folder containing the example package below)
Output of the command and what's wrong with the output
generic_type_switch.go:23:10: impossible type assertion; ExampleType[uint32] and ExampleType[T] contradict each other:
wrong type for SomeMethod method
have func() generics_exception.ExampleType[uint32]
want func() generics_exception.ExampleType[T] (SA5010)
generic_type_switch.go:25:10: impossible type assertion; ExampleType[uint64] and ExampleType[T] contradict each other:
wrong type for SomeMethod method
have func() generics_exception.ExampleType[uint64]
want func() generics_exception.ExampleType[T] (SA5010)
Where we can read the code you're running Staticcheck on
The following example is a bit contrived in order to be as minimal as possible while showing the exceptional case. What appears to be happening is that this check assumes all type assertions will be against concrete types, which works well in the general case but in this generics case we are getting an unhelpful linter message. This code does correctly run the type assertions, counter to what the linter rule suggests.
staticcheck 2022.1.3 (v0.3.3)
go version go1.18.2 linux/amd64
staticcheck
(within the folder containing the example package below)The text was updated successfully, but these errors were encountered: