Skip to content

Commit

Permalink
Merge pull request 99designs#1242 from 99designs/named_map_references
Browse files Browse the repository at this point in the history
Do not use pointers on named map types
  • Loading branch information
lwc authored Jul 10, 2020
2 parents bf99e35 + 995e771 commit fbe6e39
Show file tree
Hide file tree
Showing 25 changed files with 598 additions and 23 deletions.
6 changes: 4 additions & 2 deletions codegen/config/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,14 @@ func (b *Binder) CopyModifiersFromAst(t *ast.Type, base types.Type) types.Type {

func IsNilable(t types.Type) bool {
if namedType, isNamed := t.(*types.Named); isNamed {
t = namedType.Underlying()
return IsNilable(namedType.Underlying())
}
_, isPtr := t.(*types.Pointer)
_, isMap := t.(*types.Map)
_, isInterface := t.(*types.Interface)
return isPtr || isMap || isInterface
_, isSlice := t.(*types.Slice)
_, isChan := t.(*types.Chan)
return isPtr || isMap || isInterface || isSlice || isChan
}

func hasMethod(it types.Type, name string) bool {
Expand Down
9 changes: 1 addition & 8 deletions codegen/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,9 @@ func (b *builder) buildObject(typ *ast.Definition) (*Object, error) {
}

func (o *Object) Reference() types.Type {
switch v := o.Type.(type) {
case *types.Named:
_, isInterface := v.Underlying().(*types.Interface)
if isInterface {
return o.Type
}
case *types.Pointer, *types.Slice, *types.Map:
if config.IsNilable(o.Type) {
return o.Type
}

return types.NewPointer(o.Type)
}

Expand Down
Loading

0 comments on commit fbe6e39

Please sign in to comment.