compiler: support non-struct methods

There is no need to restrict ourselves just to structs.
This commit is contained in:
Evgenii Stratonikov 2020-05-19 16:04:41 +03:00
parent 87f6ba34db
commit 0629479560
2 changed files with 17 additions and 9 deletions

View file

@ -304,15 +304,8 @@ func (c *codegen) convertFuncDecl(file ast.Node, decl *ast.FuncDecl) {
// to support other types.
if decl.Recv != nil {
for _, arg := range decl.Recv.List {
ident := arg.Names[0]
// Currently only method receives for struct types is supported.
_, ok := c.typeInfo.Defs[ident].Type().Underlying().(*types.Struct)
if !ok {
c.prog.Err = fmt.Errorf("method receives for non-struct types is not yet supported")
return
}
// only create an argument here, it will be stored via INITSLOT
c.scope.newVariable(varArgument, ident.Name)
c.scope.newVariable(varArgument, arg.Names[0].Name)
}
}