reflect: TypeOf(nil) should be nil
Этот коммит содержится в:
родитель
a366c014c7
коммит
6768af91e7
2 изменённых файлов: 11 добавлений и 0 удалений
|
@ -465,6 +465,9 @@ func (t *rawType) isNamed() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TypeOf(i interface{}) Type {
|
func TypeOf(i interface{}) Type {
|
||||||
|
if i == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
typecode, _ := decomposeInterface(i)
|
typecode, _ := decomposeInterface(i)
|
||||||
return (*rawType)(typecode)
|
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 {
|
func equal[T comparable](a, b []T) bool {
|
||||||
if len(a) != len(b) {
|
if len(a) != len(b) {
|
||||||
return false
|
return false
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче