Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tracking of applied operator patches per walk #658

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,29 @@ func ParseCheck(input string, config *conf.Config) (*parser.Tree, error) {
}

if len(config.Visitors) > 0 {
for i := 0; i < 1000; i++ {
for {
more := false
for _, v := range config.Visitors {
// We need to perform types check, because some visitors may rely on
// types information available in the tree.
_, _ = Check(tree, config)

r, repeatable := v.(interface {
Reset()
ShouldRepeat() bool
});

if repeatable {
r.Reset()
}

ast.Walk(&tree.Node, v)

if v, ok := v.(interface {
ShouldRepeat() bool
}); ok {
more = more || v.ShouldRepeat()
if repeatable {
more = more || r.ShouldRepeat()
}
}

if !more {
break
}
Expand Down
5 changes: 5 additions & 0 deletions patcher/operator_override.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func (p *OperatorOverloading) Visit(node *ast.Node) {
}
}

// Tracking must be reset before every walk over the AST tree
func (p *OperatorOverloading) Reset() {
p.applied = false
}

func (p *OperatorOverloading) ShouldRepeat() bool {
return p.applied
}
Expand Down
Loading