reflect: TypeOf(nil) should be nil

Этот коммит содержится в:
Damian Gryski 2023-03-14 11:49:21 -07:00 коммит произвёл Ayke
родитель a366c014c7
коммит 6768af91e7
2 изменённых файлов: 11 добавлений и 0 удалений

Просмотреть файл

@ -465,6 +465,9 @@ func (t *rawType) isNamed() bool {
}
func TypeOf(i interface{}) Type {
if i == nil {
return nil
}
typecode, _ := decomposeInterface(i)
return (*rawType)(typecode)
}

Просмотреть файл

@ -313,6 +313,14 @@ func TestAddr(t *testing.T) {
}
}
func TestNilType(t *testing.T) {
var a any = nil
typ := TypeOf(a)
if typ != nil {
t.Errorf("Type of any{nil} is not nil")
}
}
func equal[T comparable](a, b []T) bool {
if len(a) != len(b) {
return false