From 85de4e198b76cce586e70258cfe7d8d7a468d125 Mon Sep 17 00:00:00 2001 From: Jamie Wilkinson Date: Mon, 24 Jun 2024 15:58:23 +0200 Subject: [PATCH] chore: reformat ast mergepositionlist because gosec is buggy `gosec` thinks that `l[0].Pos()` is an index out of range error. --- internal/runtime/compiler/ast/ast.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/runtime/compiler/ast/ast.go b/internal/runtime/compiler/ast/ast.go index 3a455dcac..f952d0a05 100644 --- a/internal/runtime/compiler/ast/ast.go +++ b/internal/runtime/compiler/ast/ast.go @@ -435,14 +435,15 @@ func (n *StopStmt) Type() types.Type { // mergepositionlist is a helper that merges the positions of all the nodes in a list. func mergepositionlist(l []Node) *position.Position { - if len(l) == 0 { + switch len(l) { + case 0: return nil - } - if len(l) == 1 { - if l[0] != nil { - return l[0].Pos() + case 1: + if l[0] == nil { + return nil } - return nil + return l[0].Pos() + default: + return position.Merge(l[0].Pos(), mergepositionlist(l[1:])) } - return position.Merge(l[0].Pos(), mergepositionlist(l[1:])) }