Skip to content

fix(astutil): unwrap parenthesized callee in shared call-matching helpers - #74277

Merged
pelikhan merged 3 commits into
mainfrom
sergo/paren-unwrap-gap-astutil-callfun-r117-a83457dc1d1686e5
Nov 3, 2026
Merged

pelikhan merged 3 commits into
mainfrom
sergo/paren-unwrap-gap-astutil-callfun-r117-a83457dc1d1686e5

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Five shared helpers in pkg/linters/internal/astutil/astutil.go type-assert call.Fun directly to *ast.SelectorExpr / *ast.Ident without UnwrapParenExpr. A call with a parenthesized callee, such as (fmt.Errorf)("x"), (os.Getenv)("K"), or (regexp.MustCompile)(p), is valid Go and type-checks to the same function. These helpers do not recognize it, so the linters that use them miss it.

This PR fixes the gap once in the shared helpers, so all 11 linters that use them get the fix. Earlier sergo PRs (R113 to R115) fixed the same class one linter at a time. R115 first found it at the call.Fun position in sortslice.

Evidence

Helper Line Downstream linters
IsFmtErrorf astutil.go:268 fmterrorfnoverbs, errorfwrapv, errormessage
CalledOSFunc astutil.go:298 osgetenvlibrary, ossetenvlibrary
AsStringsMethodCall astutil.go:597 stringsjoinone, and through NormalizeComparisonOperands/ReportStringsMethodComparison: stringsindexhasprefix, stringsindexcontains, stringscountcontains
CallQualifierText astutil.go:612 the same 3 strings comparison linters (builds the suggested-fix qualifier)
IsRegexpCompileCall astutil.go:954 regexpcompileinfunction, regexpdynamicpattern

The earlier R72 audit marked IsFmtErrorf, IsRegexpCompileCall, and AsStringsMethodCall as paren-immune. That audit only checked the sel.X package-qualifier position, where (fmt).Errorf is invalid Go. It did not check the call.Fun position, where (fmt.Errorf)(...) is valid.

CallQualifierText has to change together with AsStringsMethodCall. If only AsStringsMethodCall unwrapped, ReportStringsMethodComparison would match (strings.Index)(s, sub) >= 0, then get "" from CallQualifierText and return early without reporting. The false negative would remain.

Implementation

  • Wrap call.Fun with the existing UnwrapParenExpr in all five helpers. The behavior for unparenthesized calls stays the same.
  • I checked every consumer. None of them reads call.Fun again after calling a helper. All diagnostics and suggested fixes use the full call/expr range, so unwrapping cannot produce misplaced text edits.

Tests

New cases in astutil_test.go:

  • TestIsFmtErrorf (new): aliased format.Errorf, parenthesized (format.Errorf), and a negative case with errors.New. Type-checked through typecheckSnippet.
  • TestCalledOSFunc: parenthesized (os.Getenv) callee.
  • TestAsStringsMethodCall: parenthesized (strings.Index) callee. It also checks that the original call is returned.
  • TestCallQualifierText: parenthesized callee returns strings.
  • TestIsRegexpCompileCall: (regexp.Compile)(pattern) in the type-checked snippet. The call count goes from 3 to 4.

Validation

  • serena get_diagnostics_for_file (gopls) on astutil.go and astutil_test.go: zero diagnostics. Both files type-check cleanly.
  • serena find_referencing_symbols on CallQualifierText: the only production caller is ReportStringsMethodComparison, which matches the analysis above.
  • A repo-wide Grep for every caller of the five helpers matches the linter list in the table.
  • Not run: go test, make fmt, and make agent-report-progress. The agent sandbox denies go and make commands. CI is the first real test run, so please let CI run before merging.

Notes

  • Only Go code changed. There are no .github/workflows/ edits.
  • Other per-linter files still contain bare call.Fun assertions (for example trimleftright, timesleepnocontext, httpnoctx, execcommandwithoutcontext, and others listed by a Grep for call.Fun.(*ast.SelectorExpr)). I left them out on purpose to keep this PR limited to the shared helpers.

References: §41549681735

🤖 Generated with [Claude Code]((claude.com/redacted)

Generated by 🤖 Sergo - Serena Go Expert · claude · routed: opus55 high · ~203 AIC · ⌖ ~2 AIC · ⊞ 3.8K · ◷

  • expires on Nov 9, 2026, 4:13 PM UTC-08:00

github-actions Bot and others added 2 commits November 3, 2026 00:13
…-route-sergo

# Conflicts:
#	.github/workflows/sergo.lock.yml

Co-authored-by: SivaKesava1 <[email protected]>
@github-actions github-actions Bot added cookie Issue Monster Loves Cookies! sergo labels Nov 3, 2026
@pelikhan
pelikhan marked this pull request as ready for review November 3, 2026 00:15
Copilot AI adaptive review requested due to automatic review settings November 3, 2026 00:15
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

Design Decision Gate 🏗️

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Design Decision Gate 🏗️ · routed: gpt56 max · ~1 AIC · ⌖ ~2 AIC · ⊞ 7.7K · ◷

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Ponytail Reviewer · routed: gpt56 max · ~2 AIC · ⌖ ~1 AIC · ⊞ 118 · ◷

Generated by Ponytail Reviewer for #74277

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · sonnet50 · ~15 AIC · ⌖ ~21 AIC · ⊞ 12.7K · ◷

🧪 Test quality analysis by Test Quality Sentinel

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The regression test assigns regexp.Compile’s two return values to one blank identifier, causing a fatal type-checking error before any assertions run.

1 open issue
What changed in this PR

This PR updates shared Go AST helpers so downstream linters recognize parenthesized function calls without changing matching behavior for ordinary calls.

Changes:

  • Unwrap parenthesized callees in five shared matching and qualifier helpers.
  • Add regression cases for fmt, os, strings, and regexp calls.
  • Update helper comments to describe parenthesized-callee support.
File Description
pkg/​linters/​internal/​astutil/​astutil.go Apply parenthesis unwrapping in five shared helpers.
pkg/​linters/​internal/​astutil/​astutil_test.go Add regression coverage for parenthesized callees and aliased imports.

Review effort: Balanced (auto)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary

No blocking issues found. The helper changes consistently unwrap parenthesized callees, and the added tests cover both AST behavior and type-checked source cases.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.7K
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skills-Based Review 🧠

Applied /tdd and /diagnosing-bugs. Requesting changes because the new test added in this PR fails.

Blocking: TestIsRegexpCompileCall fails to type-check. The added _ = (regexp.Compile)(pattern) assigns a two-result call to one variable. Fix: _, _ = (regexp.Compile)(pattern). See the inline comment.

📋 Verification details
  • Ran go test ./pkg/linters/... on head 98fe57ad. The only failure is TestIsRegexpCompileCall. All other linter packages pass.
  • With the one-line fix applied locally, ./pkg/linters/internal/astutil/ passes, including TestIsFmtErrorf, TestCalledOSFunc, TestAsStringsMethodCall, TestCallQualifierText. I reverted the local change; nothing was pushed.
  • The root-cause fix is sound. All five helpers now unwrap call.Fun with UnwrapParenExpr. CallQualifierText is needed alongside AsStringsMethodCall, since ReportStringsMethodComparison calls it directly (string_comparison.go:34).
  • Not touched by this PR: errormessage still uses a bare call.Fun switch in isNewValidationErrorCall. That is a separate NewValidationError check, so it is out of scope.

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~3 AIC · ⌖ ~1 AIC · ⊞ 5.4K
Comment /matt to run again

_ = regexp.MustCompile(pattern)
_ = regexp.MustCompilePOSIX(pattern)
_ = other.Contains(pattern, pattern)
_ = (regexp.Compile)(pattern)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/tdd] This line does not compile, so TestIsRegexpCompileCall fails at type-check time: assignment mismatch: 1 variable but (regexp.Compile) returns 2 values. I reproduced this on the PR head with go test ./pkg/linters/internal/astutil/. It is the only failure across ./pkg/linters/....

💡 Suggested fix
_, _ = (regexp.Compile)(pattern)

With this change the whole astutil package passes, including the new parenthesized-callee assertions. Use _, _ = for any multi-result call in a type-checked snippet.

@copilot please address this.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Commit pushed: 7b20690

Generated by PR Finisher · copilot · auto · ~18 AIC · ⌖ ~1 AIC · ⊞ 10.7K

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

PR finisher pass:

  • Fixed TestIsRegexpCompileCall (_, _ = (regexp.Compile)(pattern)); submitted for publication, not confirmed pushed. go test/go vet on astutil pass locally; make agent-report-progress was not run.
  • Merge of main failed: the base ref was not available locally and no git credentials are available. A maintainer should update the branch.
  • Review reply/resolve deferred until the fix is published. impacted-go-tests was likely caused by the test bug; CI needs a maintainer re-trigger.

Sous-chef head: 98fe57a
Sous-chef work: 42e5d572d9d75b7168fe7d0aeda0717cc07e65ed240f6d299e6fec661214f1ac 8282cb2de0458402e7fd362a3f968734d1be9b08f1a4b88aa882d94b63dca928
Sous-chef state: c0a4facbb6bb893b1c2e447ec77e2d611d72791b9598d09a0ab9daf8f26115c9

Generated by 🏁 PR Finisher · copilot · auto · ~18 AIC · ⌖ ~1 AIC · ⊞ 10.7K · ◷

@pelikhan
pelikhan merged commit 277934f into main Nov 3, 2026
2 checks passed
@pelikhan
pelikhan deleted the sergo/paren-unwrap-gap-astutil-callfun-r117-a83457dc1d1686e5 branch November 3, 2026 01:25
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v1.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cookie Issue Monster Loves Cookies! sergo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants