mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 02:57:46 +00:00
reflect: TypeOf(nil) should be nil
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user