reflect: make Value.Comparable return true for nil interface value

Fixes #65718
This commit is contained in:
Jes Cok 2024-02-16 20:57:36 +08:00
parent daa58db486
commit c768b4532f
2 changed files with 7 additions and 1 deletions

View File

@ -8024,6 +8024,7 @@ func TestValue_Len(t *testing.T) {
}
func TestValue_Comparable(t *testing.T) {
var iNil interface{}
var a int
var s []int
var i interface{} = a
@ -8035,6 +8036,11 @@ func TestValue_Comparable(t *testing.T) {
comparable bool
deref bool
}{
{
ValueOf(&iNil).Elem(),
true,
false,
},
{
ValueOf(32),
true,

View File

@ -3413,7 +3413,7 @@ func (v Value) Comparable() bool {
return v.Type().Comparable()
case Interface:
return v.Elem().Comparable()
return v.IsNil() || v.Elem().Comparable()
case Struct:
for i := 0; i < v.NumField(); i++ {