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
In the case that works, every valid type argument will be a slice of the exact type struct{ A, b int }. Since there is only one possible type there, the compiler permits the field access.
In the case that fails, there are an infinite number of types. It's true that all of those types will have a field A. But as it says in the release notes:
The Go compiler does not support accessing a struct field x.f where x is of type parameter type even if all types in the type parameter's type set have a field f. We may remove this restriction in a future release.
Closing because this is working as expected. Making this case work is #48522.
What version of Go are you using (
go version
)?1.18 on playground and gotip on playground
Does this issue reproduce with the latest release?
Yes
What did you do?
I can access the fields of structs when the underlying type is a slice of structs:
...but not if the underlying type is just a struct:
https://go.dev/play/p/NbD6d99neQN
https://go.dev/play/p/NbD6d99neQN?v=gotip
What did you expect to see?
Program should run.
What did you see instead?
The text was updated successfully, but these errors were encountered: