mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-23 22:09:03 +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 {
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user