-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
LanguageChangeSuggested changes to the Go languageSuggested changes to the Go languageProposalv2An incompatible library changeAn incompatible library change
Milestone
Description
It's confusing that nil can be used both as a value to represent an uninitialized interface, and as a value for the pointer that an interface is initialized with. It's also very inconvenient to determine whether a pointer value in an interface is nil without casting it to the pointer type.
Proposal: use a value other than nil for uninitialized interfaces. To avoid adding new pre-defined identifiers, the value could be syntactically represented as {}, for example. This would allow expressing tests like this:
var v interface{}
...
if (v != {}) && (v != nil) {
...
}
The test against nil then doesn't need a cast and doesn't need to use the reflect package.
overcyn, jaekwon and ValarDragoncznic, akmistry, jimmyfrasche, slrz, tmthrgd and 8 morejaekwon
Metadata
Metadata
Assignees
Labels
LanguageChangeSuggested changes to the Go languageSuggested changes to the Go languageProposalv2An incompatible library changeAn incompatible library change