compiler: drop unused call results

Close #683.
This commit is contained in:
Evgenii Stratonikov 2020-08-24 18:37:39 +03:00
parent f70cb4f34a
commit e58616b975
4 changed files with 80 additions and 15 deletions

View file

@ -90,8 +90,24 @@ func (c *funcScope) analyzeVoidCalls(node ast.Node) bool {
}
case *ast.BinaryExpr:
return false
case *ast.IfStmt:
// we can't just return `false`, because we still need to process body
ce, ok := n.Cond.(*ast.CallExpr)
if ok {
c.voidCalls[ce] = false
}
case *ast.CaseClause:
for _, e := range n.List {
ce, ok := e.(*ast.CallExpr)
if ok {
c.voidCalls[ce] = false
}
}
case *ast.CallExpr:
c.voidCalls[n] = true
_, ok := c.voidCalls[n]
if !ok {
c.voidCalls[n] = true
}
return false
}
return true