Commit 9fef68f1 authored by Hugo Moreau's avatar Hugo Moreau
Browse files

Double brackets: Check modified element

To avoid collision since we modify IndexExpr and nested IndexExpr, we
now use a map to check if the element has already been modified.

 * transform/double_brackets.go: Here.
parent c66354c8
Pipeline #27068 passed with stage
in 2 minutes and 32 seconds
......@@ -38,6 +38,7 @@ G2PState[1 + G2PState[2 + 1]] = 1
*/
type DoubleBrackets struct {
exploredIndExpr map[*ast.IndexExpr]bool
currentFuncName string
}
......@@ -45,8 +46,13 @@ type DoubleBrackets struct {
func (t *DoubleBrackets) Pre(meta *Meta, v *Visitor) bool {
c := v.Cursor()
switch node := c.Node().(type) {
case *ast.File:
t.exploredIndExpr = make(map[*ast.IndexExpr]bool)
case *ast.IndexExpr:
c.Replace(indexExprRec(node, nil))
if _, ok := t.exploredIndExpr[node]; !ok {
c.Replace(indexExprRec(node, nil))
t.exploredIndExpr[node] = true
}
}
return true
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment