-
Notifications
You must be signed in to change notification settings - Fork 18k
Proof that golang's interface type (nil) current judgement is wrong #67879
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
There is nothing proposed here. |
@gophun @seankhliao @ALTree https://go.dev/play/p/KTHiMoUDAJY
|
There won't be a Go 2: https://go.dev/blog/compat#go2
Unsafe code is not covered by the compatibility promise: https://go.dev/doc/go1compat#expectations "Use of package unsafe. Packages that import unsafe may depend on internal properties of the Go implementation. We reserve the right to make changes to the implementation that may break such programs." |
@gophun I think OP is referring to a conversation that was had on another (now closed) issue. It's appreciated. As discussed in that issue, it can be implemented in a forward compatible way but not sure it is worth it. The issue being that it would somehow impose a version on the code examples found at large since semantics would be substituted. To be fair, one advantage would also be that we could remove the need for errors.Is and errors.As in favor of already established operations. But hey, this probably has to be examined in the context of a larger potential revamp of error handling if required and that can't happen if it is not frictionless. |
Proposal Details
Example:
var a *st //struct
if a==nil //true,yes
var b = any(a) //
a0,yes := b.(*st)
if yes==true //true,yes
if a0==nil//true,yes
if b==nil//(false, yes or no?) The problem arises here when someone argues that this judgement should not hold, based on the type assertion (a0,yes := b.(*st)).
But I think this is wrong, the if b==nil judgement should be based on a value judgement (true,yes), not on a type judgement (false,no). If you make a type judgement
(a0,yes := b.(*st)) is sufficient, the only thing missing is the value judgement of the interface type (essentially the compiler is judging two interfaces of the same type by the value judgement, which is a bit confusing).
Interface type occupies two pointers {typeinfo_ptr, value_ptr}, we should take the judgement (value_ptr) judgement (nil), such as integers (0==0, 1!=0), pointers can also be understood as a kind of value. The following connection example causes problems exactly what I said!
https://go.dev/play/p/pnVn1mT6Keg
The text was updated successfully, but these errors were encountered: