Skip to content

Go: fix some duplicate results in go/unreachable-statement - #22679

Merged
owen-mc merged 6 commits into
github:mainfrom
owen-mc:go/fix/unreachable-statement-allowlist
Sep 28, 2026
Merged

owen-mc merged 6 commits into
github:mainfrom
owen-mc:go/fix/unreachable-statement-allowlist

Conversation

@owen-mc

@owen-mc owen-mc commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

We deliberately only report the first unreachable statement in a run of them. We also have an allowlist of statements we won't report. But the two features were interacting badly - if the first unreachable statement in a run was in the allowlist them we weren't reporting anything. This PR fixes that, so we report the first unreachable statement in a run which isn't in the allowlist. A test has been added to demonstrate the bug and show that it is fixed.

This does not need a change note as it is fixing FPs that haven't been in any release.

@owen-mc
owen-mc requested a review from a team September 24, 2026 14:32
@owen-mc
owen-mc requested a review from a team as a code owner September 24, 2026 14:32
Copilot AI balanced review requested due to automatic review settings September 24, 2026 14:32
@owen-mc owen-mc added the no-change-note-required This PR does not need a change note label Sep 24, 2026

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.

Copilot review overview

🔵 Needs a closer look

Unreachable empty statements can still prevent the first reportable statement from being selected.

Review effort: Balanced
Findings: None

What changed in this PR

Updates go/unreachable-statement to report the first non-allowlisted statement after an allowlisted unreachable prefix.

Changes:

  • Adds recursive allowlisted-prefix handling.
  • Adds regression coverage and updates expected results.

Review findings:

  • Moderate: Unreachable empty statements still break traversal and can suppress an alert.
  • Nit: Add coverage for multiple consecutive allowlisted statements.
  • Nit: Update PR metadata to describe a missing-result/false-negative fix.
File Description
go/​ql/​test/​query-tests/​RedundantCode/​UnreachableStatement/​UnreachableStatement.expected Records the new expected alert.
go/​ql/​test/​query-tests/​RedundantCode/​UnreachableStatement/​main.go Adds regression coverage.
go/​ql/​test/​query-tests/​RedundantCode/​UnreachableStatement/​CONSISTENCY/​CfgConsistency.expected Updates CFG consistency expectations.
go/​ql/​src/​RedundantCode/​UnreachableStatement.ql Refines unreachable-statement selection.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions github-actions Bot added the Go label Sep 24, 2026
@owen-mc
owen-mc force-pushed the go/fix/unreachable-statement-allowlist branch from 4cf5529 to 77b370d Compare September 25, 2026 15:37
@owen-mc
owen-mc force-pushed the go/fix/unreachable-statement-allowlist branch from 77b370d to 31b8064 Compare September 28, 2026 09:43

@michaelnebel michaelnebel 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.

Cool to get this fixed.
Is there a DCA run?

Comment thread go/ql/src/RedundantCode/UnreachableStatement.ql
Comment thread go/ql/src/RedundantCode/UnreachableStatement.ql Outdated

@michaelnebel michaelnebel 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.

LGTM!

@owen-mc
owen-mc merged commit 0580587 into github:main Sep 28, 2026
17 checks passed
@owen-mc
owen-mc deleted the go/fix/unreachable-statement-allowlist branch September 28, 2026 15:07
@owen-mc

owen-mc commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

DCA showed nothing.

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

Labels

Go no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants