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
Due to learn the issue #70364 I would like to make a proposal:
way one: Because nil is suitable value for any interface, it should be possible to check a value is nll despite some function return nil as a pointer to the concrete type that implements this interface
OR
way two: nil should not to be suitable as value for any interface (As it usually working)
I, personally, mean that it is not correct way to mess pointer and reference, so passing nil as a reference should be prohibited
package main
import (
"fmt"
)
typeUnwrapableinterface {
Unwrap() error
}
typeTestStructstruct {
errerror
}
func (err*TestStruct) Unwrap() error {
returnerr.err
}
funcdoSomethingElse() *TestStruct {
returnnil
}
funcHandleUnwrapable(errUnwrapable) {
// should be possible ever by the way oneiferr!=nil {
fmt.Printf("err: Not nil, type: %T, address: %p\n", err, err)
} else {
fmt.Printf("err: Nil, type: %T, address: %p\n", err, err)
}
}
funcmain() {
test:=doSomethingElse()
iftest!=nil {
fmt.Printf("err: Not nil, type: %T, address: %p\n", test, test)
} else {
fmt.Printf("err: Nil, type: %T, address: %p\n", test, test)
}
HandleUnwrapable(test) // should be prohibited by the way two// Output// err: Nil, type: *main.TestStruct, address: 0x0// err: Not nil, type: *main.TestStruct, address: 0x0 - unexpected
}
Others languages behaviour with nil reference
The text was updated successfully, but these errors were encountered:
This has been already discussed before and you need a story on how to do without introducing a backward breaking change to the language for a proposal like this to be considerable.
Proposal Details
Due to learn the issue #70364 I would like to make a proposal:
way one: Because nil is suitable value for any interface, it should be possible to check a value is nll despite some function return nil as a pointer to the concrete type that implements this interface
OR
way two: nil should not to be suitable as value for any interface (As it usually working)
I, personally, mean that it is not correct way to mess pointer and reference, so passing nil as a reference should be prohibited
Others languages behaviour with nil reference

The text was updated successfully, but these errors were encountered: