-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: Go 2: introduce interface type to solve nil comparison dilemma #43269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@ianlancetaylor well, this works assuming that the error is not pointer to a struct as shown on the faq (https://golang.org/doc/faq#nil_error). however, introducing this new type would also solve for checking interfaces in general. with the amount of Go code out there, we're leveraging a lot of libraries that we can't validate. we don't know if they're returning a "nil" pointer to struct, either for an error or some other typed interface. since error is an interface, this type of issue can arise. |
When talking about language semantics at this level of detail, it's essential to be really precise.
When you say that it doesn't work if the error is a pointer to a struct, you probably mean something like If we want different behavior, that behavior has to be specified precisely, just as the current behavior is specified precisely. In order to change the language, you need to provide that precise specification. |
Based on the discussion above, this is a likely decline. Leaving open for four weeks for final comments. |
ok. sorry was on vacation. will be updating our code to use a func to validate specific interface checks that could be problematic. thanks. |
No change in consensus. |
There's a lot of discussion regarding comparing interfaces to nil (https://golang.org/doc/faq#nil_error, #22729). I recently had to deal with this, and as a developer, I'm surprised we haven't had more issues since errors are interfaces. It is not a trivial issue to solve.
My humble suggestion is to introduce another type with new semantics.
We would migrate the error type so that
err != nil
orerr == nil
always works. The new type would be interoperable with a regular or typed interfaces. It should essentially work the same except for comparisons, where the new semantics could then be introduced.Developers could then start migrating their code to use this new type as needed, so that existing code doesn't have to be changed immediately and we don't introduce any breaking changes.
Thoughts? Comments?
The text was updated successfully, but these errors were encountered: