proposal: spec: use zero receiver for value method invoked via nil pointer #18775
Labels
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Proposal
v2
A language change or incompatible library change
Milestone
Currently, if a method is defined on a value type, that method is also
part of the method set of the pointer type. However, if that method
is called on the nil pointer, it panics.
This means there's no way to define a method that works on all possible
values and pointer values for a type.
I propose that when a value method is called on a nil pointer, instead of panicking,
the method is invoked on the zero value for the type.
As this breaks code that currently relies on catching this panic (notably the
fmt package), it is probably sufficiently backwardly incompatible to justify
the Go2 tag.
The text was updated successfully, but these errors were encountered: