reflect: TypeOf(nil) should be nil

This commit is contained in:
Damian Gryski
2023-03-14 11:49:21 -07:00
committed by Ayke
parent a366c014c7
commit 6768af91e7
2 changed files with 11 additions and 0 deletions
+3
View File
@@ -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)
}
+8
View File
@@ -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