gotypes: add missing Underlying() calls (#78)

Issue #77 pointed out that in the case of named array types, the gotypes Components type fails to recognize the underlying type as an array. In fact this problem was more widespread. This diff fixes the missing calls to Underlying() and adds some test cases.

Fixes #77
This commit is contained in:
Michael McLoughlin
2019-04-13 18:50:51 -04:00
committed by GitHub
parent 138eaf8dc3
commit d0da7e47ad
2 changed files with 134 additions and 4 deletions

View File

@@ -143,7 +143,7 @@ func (c *component) Imag() Component {
}
func (c *component) Index(i int) Component {
a, ok := c.typ.(*types.Array)
a, ok := c.typ.Underlying().(*types.Array)
if !ok {
return errorf("not array type")
}
@@ -213,17 +213,17 @@ func (c *component) sub(suffix string, offset int, t types.Type) *component {
}
func isslice(t types.Type) bool {
_, ok := t.(*types.Slice)
_, ok := t.Underlying().(*types.Slice)
return ok
}
func isstring(t types.Type) bool {
b, ok := t.(*types.Basic)
b, ok := t.Underlying().(*types.Basic)
return ok && b.Kind() == types.String
}
func iscomplex(t types.Type) bool {
b, ok := t.(*types.Basic)
b, ok := t.Underlying().(*types.Basic)
return ok && (b.Info()&types.IsComplex) != 0
}