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 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.
till GO 1.23 this restriction is not removed yet.
for example:
replacing func egressRuleSelectsPeer(rulePeers []apisv1a.AdminNetworkPolicyEgressPeer, dst Peer) (bool, error) and func ingressRuleSelectsPeer(rulePeers []apisv1a.AdminNetworkPolicyIngressPeer, src Peer) (bool, error)
with a func using generics like this : func xgressRuleSelectsPeer[T apisv1a.AdminNetworkPolicyEgressPeer | apisv1a.AdminNetworkPolicyIngressPeer](rulePeers []T, dst Peer) (bool, error)
will fail with errors such as : rulePeers[i].Namespaces undefined (type T has no field or method Namespaces)
a useful way to skip the errors is to define an interface with some Getter funcs to be implemented on the "inheriting types"
of the parameters.
but in this case : since our parameters are not of local types, we can not define new methods (like getters) on them;
not even with using aliases since then we'll need to copy values in calling funcs into the aliases and
this is not more efficient than current solutions.
@todo: if GO is upgraded to a release that does not has this restriction on types with same fields, replace following two "duplicated" funcs with one func that uses generics type
following two funcs egressRuleSelectsPeer and ingressRuleSelectsPeer:
(same for updateConnsIfEgressRuleSelectsPeer and updateConnsIfIngressRuleSelectsPeer and maybe other funcs)
The text was updated successfully, but these errors were encountered:
why could not success yet with using generics to avoid duplicates in
eval/k8s/adminnetpol.go
?according to https://tip.golang.org/doc/go1.18#generics :
till GO 1.23 this restriction is not removed yet.
for example:
replacing
func egressRuleSelectsPeer(rulePeers []apisv1a.AdminNetworkPolicyEgressPeer, dst Peer) (bool, error)
andfunc ingressRuleSelectsPeer(rulePeers []apisv1a.AdminNetworkPolicyIngressPeer, src Peer) (bool, error)
with a func using generics like this :
func xgressRuleSelectsPeer[T apisv1a.AdminNetworkPolicyEgressPeer | apisv1a.AdminNetworkPolicyIngressPeer](rulePeers []T, dst Peer) (bool, error)
will fail with errors such as :
rulePeers[i].Namespaces undefined (type T has no field or method Namespaces)
a useful way to skip the errors is to define an interface with some
Getter
funcs to be implemented on the "inheriting types"of the parameters.
but in this case : since our parameters are not of local types, we can not define new methods (like getters) on them;
not even with using aliases since then we'll need to copy values in calling funcs into the aliases and
this is not more efficient than current solutions.
@todo: if GO is upgraded to a release that does not has this restriction on types with same fields, replace following two "duplicated" funcs with one func that uses generics type
following two funcs
egressRuleSelectsPeer
andingressRuleSelectsPeer
:(same for
updateConnsIfEgressRuleSelectsPeer
andupdateConnsIfIngressRuleSelectsPeer
and maybe other funcs)The text was updated successfully, but these errors were encountered: