From 0607cf7d22e7e22f855d634c822b6d7c2a62eb95 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:02:56 +0000 Subject: [PATCH] refactor(runtime): clear the three Sonar smells left on develop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit eachUnwrappedDeclMember and unwrappedDeclMembers opened with the same three-way dispatch — ast.OwnedConstraintOf, then a type switch over the assume and require members — although the first check only ever answers for those same two node types and returns their Body unchanged. Both now call one helper, constraintMemberBody, so the iterator keeps a single yield loop and its cognitive complexity drops from 33 to 17 (go:S3776). The member sequence each reader yields is unchanged for every declaration kind, and the helper inlines and allocates nothing. Two `got :=` variables in validate_test.go that were only read in their if condition are inlined (godre:S8193). Co-Authored-By: jason.han --- internal/exec/runtime/invoke_calc.go | 42 ++++++++++--------------- internal/frontend/grpc/validate_test.go | 4 +-- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/internal/exec/runtime/invoke_calc.go b/internal/exec/runtime/invoke_calc.go index c194f30701..39b2dfb2c1 100644 --- a/internal/exec/runtime/invoke_calc.go +++ b/internal/exec/runtime/invoke_calc.go @@ -1608,14 +1608,8 @@ func isStateSymbol(sym *symbols.Symbol) bool { // unwrappedDeclMembers is ast.DeclMembers extended to named owned constraints, // with the Membership wrappers the parser produces unwrapped. func unwrappedDeclMembers(decl ast.Node) []ast.Node { - if oc, ok := ast.OwnedConstraintOf(decl); ok { - return oc.Body - } - switch m := decl.(type) { - case *ast.AssumeMember: - return m.Body - case *ast.RequireMember: - return m.Body + if body, ok := constraintMemberBody(decl); ok { + return body } members := ast.DeclMembers(decl) if members == nil { @@ -1629,28 +1623,24 @@ func unwrappedDeclMembers(decl ast.Node) []ast.Node { return out } +// constraintMemberBody returns the nested members of an assume or require member +// in either of its forms, and false for every other declaration. +func constraintMemberBody(decl ast.Node) ([]ast.Node, bool) { + switch m := decl.(type) { + case *ast.AssumeMember: + return m.Body, true + case *ast.RequireMember: + return m.Body, true + } + return nil, false +} + // eachUnwrappedDeclMember yields what unwrappedDeclMembers lists without building the list, // for the readers that stop at the first member of interest. func eachUnwrappedDeclMember(decl ast.Node) iter.Seq[ast.Node] { return func(yield func(ast.Node) bool) { - if oc, ok := ast.OwnedConstraintOf(decl); ok { - for _, member := range oc.Body { - if !yield(member) { - return - } - } - return - } - switch m := decl.(type) { - case *ast.AssumeMember: - for _, member := range m.Body { - if !yield(member) { - return - } - } - return - case *ast.RequireMember: - for _, member := range m.Body { + if body, ok := constraintMemberBody(decl); ok { + for _, member := range body { if !yield(member) { return } diff --git a/internal/frontend/grpc/validate_test.go b/internal/frontend/grpc/validate_test.go index a0c46bf0e4..5037f07758 100644 --- a/internal/frontend/grpc/validate_test.go +++ b/internal/frontend/grpc/validate_test.go @@ -325,7 +325,7 @@ func TestValidateAndVerifyLabelASubsettingObjectByItsDeclaration(t *testing.T) { } want := []string{"small", "smalls[1]", "smalls[2]"} for _, kind := range []string{"constraint", "satisfy"} { - if got := strings.Join(paths[kind], " "); got != strings.Join(want, " ") { + if strings.Join(paths[kind], " ") != strings.Join(want, " ") { t.Errorf("ValidateInstance %s paths = %q, want %q", kind, paths[kind], want) } } @@ -338,7 +338,7 @@ func TestValidateAndVerifyLabelASubsettingObjectByItsDeclaration(t *testing.T) { for _, v := range satisfied.Verdicts { swept = append(swept, v.InstancePath) } - if got := strings.Join(swept, " "); got != strings.Join(want, " ") { + if strings.Join(swept, " ") != strings.Join(want, " ") { t.Errorf("VerifySatisfaction paths = %q, want %q", swept, want) } }