| func scanToDeferLine(fileset *token.FileSet, node ast.Node, lineNum int) ast.Node { |
| ast.Inspect(node, func(node ast.Node) bool { |
| case node == nil || matchedNode != nil: |
| case fileset.Position(node.End()).Line == lineNum: |
| if funcLit, ok := node.(*ast.FuncLit); ok { |
| debug("defer line node: %s", debugFormatNode{matchedNode}) |
| func guessDefer(node ast.Node) (ast.Node, error) { |
| defers := collectDefers(node) |
| return nil, errors.New("failed to expression in defer") |
| return defers[0].Call, nil |
| return nil, errors.Errorf( |
| "ambiguous call expression: multiple (%d) defers in call block", |
| func collectDefers(node ast.Node) []*ast.DeferStmt { |
| var defers []*ast.DeferStmt |
| ast.Inspect(node, func(node ast.Node) bool { |
| if d, ok := node.(*ast.DeferStmt); ok { |
| defers = append(defers, d) |
| debug("defer: %s", debugFormatNode{d}) |