Skip to content

nilctxpassed: ignore variadic spread slice arguments to prevent false positives - #45906

Merged
pelikhan merged 4 commits into
mainfrom
copilot/fix-nilctxpassed-issue
Jul 16, 2026
Merged

nilctxpassed: ignore variadic spread slice arguments to prevent false positives#45906
pelikhan merged 4 commits into
mainfrom
copilot/fix-nilctxpassed-issue

Conversation

Copilot AI commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

nilctxpassed incorrectly flagged f(nil...) for variadic ...context.Context params by treating a spread slice argument as an individual context.Context element. This produced a factually wrong diagnostic for valid nil-slice variadic calls.

  • Analyzer logic: variadic spread handling

    • In pkg/linters/nilctxpassed/nilctxpassed.go, the variadic branch now skips element-wise nil checks when the call uses ... on the final variadic argument (call.Ellipsis.IsValid() at the variadic slice position).
    • This preserves existing behavior for non-spread variadic calls (e.g., f(nil) is still reportable).
  • Regression coverage: spread vs non-spread

    • In pkg/linters/nilctxpassed/testdata/src/nilctxpassed/nilctxpassed.go, added fixtures for:
      • takesVariadicCtx(nil...) → not flagged
      • takesVariadicCtx(existingSlice...) → not flagged
    • Existing takesVariadicCtx(nil) fixture remains flagged.
if sig.Variadic() && params.Len() > 0 && i >= params.Len()-1 {
    if call.Ellipsis.IsValid() && i == len(call.Args)-1 {
        // Spread passes the variadic slice, not an element.
        continue
    }
    sliceType, ok := params.At(params.Len() - 1).Type().(*types.Slice)
    if !ok {
        continue
    }
    paramType = sliceType.Elem()
}

Copilot AI and others added 2 commits July 16, 2026 05:15
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix nilctxpassed false positive for variadic context calls nilctxpassed: ignore variadic spread slice arguments to prevent false positives Jul 16, 2026
Copilot AI requested a review from pelikhan July 16, 2026 05:21
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot merge main and recompile

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

@copilot merge main and recompile

Done in 0de7c39 — merged main into this branch and ran make recompile.

@pelikhan
pelikhan marked this pull request as ready for review July 16, 2026 06:25
Copilot AI review requested due to automatic review settings July 16, 2026 06:25
@pelikhan
pelikhan merged commit 6e77211 into main Jul 16, 2026
19 checks passed
@pelikhan
pelikhan deleted the copilot/fix-nilctxpassed-issue branch July 16, 2026 06:25

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

Fixes a nilctxpassed false positive for nil variadic slice spreads.

Changes:

  • Skips element-level checks for spread variadic arguments.
  • Adds regression fixtures for nil and existing slice spreads.
Show a summary per file
File Description
pkg/linters/nilctxpassed/nilctxpassed.go Corrects variadic spread analysis.
pkg/linters/nilctxpassed/testdata/src/nilctxpassed/nilctxpassed.go Adds spread-call regression coverage.

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: 0
  • Review effort level: Medium

@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.82.10

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

Labels

None yet

Projects

None yet

3 participants