Skip to content

reflect: ArrayOrSliceType is implemented by many other types too. #1530

@rogpeppe

Description

@rogpeppe
This just bit me. I had assumed (without looking into it too much) that
if you do,

if x, ok := x.(reflect.ArrayOrSliceType); ok {
}

then the type of x would be one of *reflect.ArrayType or *reflect.SliceType
within the body of the if.

This is not the case. The interface is also implemented by
*MapType, *PtrType and *ChanType.

Perhaps it might be worth considering making the interface
a little more exclusive to help in avoiding this pitfall.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions