Skip to content

panicinlibrarycode: recognize sync.OnceValue/OnceFunc panic exemptions - #48956

Merged
pelikhan merged 2 commits into
mainfrom
copilot/deep-report-fix-panicinlibrarycode-linter
Jul 29, 2026
Merged

panicinlibrarycode: recognize sync.OnceValue/OnceFunc panic exemptions#48956
pelikhan merged 2 commits into
mainfrom
copilot/deep-report-fix-panicinlibrarycode-linter

Conversation

Copilot AI commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

panicinlibrarycode only exempted sync.Once.Do(func(){...}) and missed equivalent Go 1.21+ lazy-init patterns (sync.OnceValue / sync.OnceFunc). That created a governance gap where exemption behavior depended on panic message text (BUG:) rather than call-site semantics.

  • Analyzer exemption expansion

    • Generalized sync-once callback detection from Once.Do-only to all supported sync-once initializer forms.
    • Added selector extraction for call expressions (including indexed call forms) and symbol/package checks to ensure exemptions apply only to sync.OnceValue / sync.OnceFunc / (*sync.Once).Do.
  • Behavioral consistency

    • Preserves existing Once.Do handling.
    • Aligns all sync-once lazy-init idioms under the same exemption rule, removing accidental reliance on panic string prefixes.
  • Focused test coverage

    • Added analyzer testdata cases with panics inside:
      • sync.OnceValue(func() T { ... })
      • sync.OnceFunc(func() { ... })
    • These cases are intentionally non-BUG: panic messages to validate semantic exemption logic.
var onceValue = sync.OnceValue(func() int {
	panic("lazy init failure in sync.OnceValue") // should not be flagged
	return 0
})

var onceFunc = sync.OnceFunc(func() {
	panic("lazy init failure in sync.OnceFunc") // should not be flagged
})

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix linter blind spot for sync.OnceValue/OnceFunc panics panicinlibrarycode: recognize sync.OnceValue/OnceFunc panic exemptions Jul 29, 2026
Copilot AI requested a review from pelikhan July 29, 2026 18:20
@pelikhan
pelikhan marked this pull request as ready for review July 29, 2026 18:35
Copilot AI review requested due to automatic review settings July 29, 2026 18:35
@pelikhan
pelikhan merged commit 89a7ee8 into main Jul 29, 2026
31 checks passed
@pelikhan
pelikhan deleted the copilot/deep-report-fix-panicinlibrarycode-linter branch July 29, 2026 18:35

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.

Pull request overview

Extends the panic linter’s sync.Once exemption to Go 1.21 lazy-initialization helpers.

Changes:

  • Recognizes sync.OnceValue and sync.OnceFunc callbacks.
  • Adds selector and generic-call handling.
  • Adds focused analyzer test cases.
Show a summary per file
File Description
pkg/linters/panic-in-library-code/panic-in-library-code.go Generalizes sync-once callback detection.
pkg/linters/panic-in-library-code/testdata/src/panicinlibrarycode/panicinlibrarycode.go Tests OnceValue and OnceFunc exemptions.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Medium

}

func isSyncOnceConstructorCall(pass *analysis.Pass, sel *ast.SelectorExpr) bool {
return isSyncPackageFunc(pass, sel, "OnceValue", "OnceFunc")
@github-actions

Copy link
Copy Markdown
Contributor

Triage: bug (linter fix)

Risk: low | Priority: medium (score 48/100)

Breakdown: impact 20/50 (narrow linter-analyzer scope, 2 files) · urgency 15/30 (CI fully green) · quality 13/20 (good description, has test data, no reviews yet)

Recommended action: batch_review (group with other small low-risk lint/tooling PRs)

All CI checks passing. Small, well-scoped fix to panicinlibrarycode analyzer exemptions.

Generated by 🔧 PR Triage Agent · aut00 · 40.7 AIC · ⌖ 5.25 AIC · ⊞ 7.9K ·

@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.84.0

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[deep-report] Fix panicinlibrarycode linter blind spot: sync.OnceValue/OnceFunc panics not exempted

3 participants