From 3a2706036ca00979ae9ef828882d5be830fa244b Mon Sep 17 00:00:00 2001 From: Ryan Bullock Date: Wed, 22 May 2024 09:20:23 -0700 Subject: [PATCH 1/2] Reset tracking of applied operator overloads before every walk of the ast tree. --- checker/checker.go | 16 ++++++++++++---- patcher/operator_override.go | 5 +++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/checker/checker.go b/checker/checker.go index c71a98f0..f191c30a 100644 --- a/checker/checker.go +++ b/checker/checker.go @@ -29,14 +29,22 @@ func ParseCheck(input string, config *conf.Config) (*parser.Tree, error) { // 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 } diff --git a/patcher/operator_override.go b/patcher/operator_override.go index 551fe09b..886ae2a4 100644 --- a/patcher/operator_override.go +++ b/patcher/operator_override.go @@ -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 } From 4dd49bdc1053f0a14ab14315945d08f4969d59fe Mon Sep 17 00:00:00 2001 From: Ryan Bullock Date: Wed, 22 May 2024 09:23:31 -0700 Subject: [PATCH 2/2] Remove limit on operator overload resolution --- checker/checker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checker/checker.go b/checker/checker.go index f191c30a..cef2c012 100644 --- a/checker/checker.go +++ b/checker/checker.go @@ -22,7 +22,7 @@ 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