Repository navigation
fix(astutil): unwrap parenthesized callee in shared call-matching helpers - #74277
Conversation
…-route-sergo # Conflicts: # .github/workflows/sergo.lock.yml Co-authored-by: SivaKesava1 <[email protected]>
|
✅ 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: 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.
|
|
✅ Ponytail Reviewer completed successfully! Ponytail ReviewerOutcome: 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.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ PR Code Quality Reviewer completed the code quality review.
|
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: 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.
|
There was a problem hiding this comment.
🟡 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, andregexpcalls. - 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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 head98fe57ad. The only failure isTestIsRegexpCompileCall. All other linter packages pass. - With the one-line fix applied locally,
./pkg/linters/internal/astutil/passes, includingTestIsFmtErrorf,TestCalledOSFunc,TestAsStringsMethodCall,TestCallQualifierText. I reverted the local change; nothing was pushed. - The root-cause fix is sound. All five helpers now unwrap
call.FunwithUnwrapParenExpr.CallQualifierTextis needed alongsideAsStringsMethodCall, sinceReportStringsMethodComparisoncalls it directly (string_comparison.go:34). - Not touched by this PR:
errormessagestill uses a barecall.Funswitch inisNewValidationErrorCall. That is a separateNewValidationErrorcheck, 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) |
There was a problem hiding this comment.
[/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.
|
Commit pushed:
|
|
PR finisher pass:
Sous-chef head: 98fe57a
|
|
🎉 This pull request is included in a new release. Release: |

Summary
Five shared helpers in
pkg/linters/internal/astutil/astutil.gotype-assertcall.Fundirectly to*ast.SelectorExpr/*ast.IdentwithoutUnwrapParenExpr. 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.Funposition insortslice.Evidence
IsFmtErrorfCalledOSFuncAsStringsMethodCallNormalizeComparisonOperands/ReportStringsMethodComparison: stringsindexhasprefix, stringsindexcontains, stringscountcontainsCallQualifierTextIsRegexpCompileCallThe earlier R72 audit marked
IsFmtErrorf,IsRegexpCompileCall, andAsStringsMethodCallas paren-immune. That audit only checked thesel.Xpackage-qualifier position, where(fmt).Errorfis invalid Go. It did not check thecall.Funposition, where(fmt.Errorf)(...)is valid.CallQualifierTexthas to change together withAsStringsMethodCall. If onlyAsStringsMethodCallunwrapped,ReportStringsMethodComparisonwould match(strings.Index)(s, sub) >= 0, then get""fromCallQualifierTextand return early without reporting. The false negative would remain.Implementation
call.Funwith the existingUnwrapParenExprin all five helpers. The behavior for unparenthesized calls stays the same.call.Funagain after calling a helper. All diagnostics and suggested fixes use the fullcall/exprrange, so unwrapping cannot produce misplaced text edits.Tests
New cases in
astutil_test.go:TestIsFmtErrorf(new): aliasedformat.Errorf, parenthesized(format.Errorf), and a negative case witherrors.New. Type-checked throughtypecheckSnippet.TestCalledOSFunc: parenthesized(os.Getenv)callee.TestAsStringsMethodCall: parenthesized(strings.Index)callee. It also checks that the original call is returned.TestCallQualifierText: parenthesized callee returnsstrings.TestIsRegexpCompileCall:(regexp.Compile)(pattern)in the type-checked snippet. The call count goes from 3 to 4.Validation
serena get_diagnostics_for_file(gopls) onastutil.goandastutil_test.go: zero diagnostics. Both files type-check cleanly.serena find_referencing_symbolsonCallQualifierText: the only production caller isReportStringsMethodComparison, which matches the analysis above.go test,make fmt, andmake agent-report-progress. The agent sandbox deniesgoandmakecommands. CI is the first real test run, so please let CI run before merging.Notes
.github/workflows/edits.call.Funassertions (for example trimleftright, timesleepnocontext, httpnoctx, execcommandwithoutcontext, and others listed by a Grep forcall.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)