compile-time assert numControllers == len(controllersArray)#3924
Conversation
|
Hi @syedriko. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
/ok-to-test |
|
While this does nicely exercise the language gymnastics, I am not a big fan of those checks because Go specifically has no assert by design: https://golang.org/doc/faq#assertions |
|
My motivation was in early detection of a violation, instead of leaving it until runtime. I don't think this check is very different from the very widespread one, that checks for interface conformance, like here
That paragraph is a bit too generic IMO, it seems like it's talking about an equivalent of assert() from C/C++, which can be pretty evil. The Go language spec is fine with type assertions though https://golang.org/ref/spec#Type_assertions. IMO, the API in this area needs to be reworked to eliminate the circular dependency with the number of controllers and remove the need for this check in the first place. |
|
Well, type assertion is just a downcast :-) |
|
I find this pretty hard to read. We have e2e tests that will catch the error. |
|
@n3wscott, could you take another look? |
|
I approved the equivalent change in knative/eventing#1112. The "assertion" is unusual but good insurance to avoid debugging an incorrect We are already circumventing language design every time we assert an interface type and every time we use I agree with @syedriko that the real fix is to remove the need to specify |
|
/cc @markusthoemmes , could you take a look at this? |
markusthoemmes
left a comment
There was a problem hiding this comment.
I agree with @grantr
/approve
Let's let it burn our eyes until we decide to fix it for good. I don't want to overrule the other opinions here though.
@vagababov strong opinion on your end?
|
Hmm I can't approve that. doh. /lgtm then! |
|
/cc @tcnghia, what's your take? |
|
/lgtm |
| // Build all of our controllers, with the clients constructed above. | ||
| // Add new controllers to this array. | ||
| controllers := []*controller.Impl{ | ||
| controllers := [...]*controller.Impl{ |
There was a problem hiding this comment.
If we're only concerned about the upper bound then you could just have this line be[numControllers]*controller.Impl
Then you can drop the compile time assertion below - since the compiler will complain if this array has more that numController elements
There was a problem hiding this comment.
But it won't if there're less: knative/eventing#1112 (comment)
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: markusthoemmes, syedriko The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/test pull-knative-serving-upgrade-tests |
Replace a runtime check with a compile-time assert in controller mainline
Sister PR in eventing knative/eventing#1112