compiler: inline expressions with type conversions, fix #1879

Don't count `string(data)` or `[]byte(data)` as function calls.
This commit is contained in:
Evgeniy Stratonikov 2021-05-25 16:17:40 +03:00
parent 6b3afe9131
commit 1d6d7206e9
4 changed files with 48 additions and 9 deletions

View file

@ -140,9 +140,22 @@ func (c *codegen) processNotify(f *funcScope, args []ast.Expr) {
func (c *codegen) hasCalls(expr ast.Expr) bool {
var has bool
ast.Inspect(expr, func(n ast.Node) bool {
_, ok := n.(*ast.CallExpr)
if ok {
has = true
ce, ok := n.(*ast.CallExpr)
if !has && ok {
isFunc := true
fun, ok := ce.Fun.(*ast.Ident)
if ok {
_, isFunc = c.getFuncFromIdent(fun)
} else {
var sel *ast.SelectorExpr
sel, ok = ce.Fun.(*ast.SelectorExpr)
if ok {
name, _ := c.getFuncNameFromSelector(sel)
_, isFunc = c.funcs[name]
fun = sel.Sel
}
}
has = isFunc || fun.Obj != nil && (fun.Obj.Kind == ast.Var || fun.Obj.Kind == ast.Fun)
}
return !has
})