Skip to content

Go: add isParenthesized relation to keep track of parentheses around expressions - #22605

Merged
owen-mc merged 3 commits into
github:mainfrom
owen-mc:go/is-parenthesized
Sep 18, 2026
Merged

owen-mc merged 3 commits into
github:mainfrom
owen-mc:go/is-parenthesized

Conversation

@owen-mc

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

Copy link
Copy Markdown
Contributor

Builds on #22182 . We no longer extract ParenExpr, so information about whether an expression had parentheses about it was lost. It is occasionally useful, so we put it in a separate table. The upgrade scripts and downgrade scripts lose this information, but this is not very important.

Comment thread go/ql/lib/printCfg.ql Fixed
Comment thread go/ql/lib/printCfg.ql Fixed
Comment thread go/ql/lib/printCfg.ql Fixed
Comment thread go/ql/lib/printCfg.ql Fixed
Comment thread go/ql/lib/printCfg.ql Fixed
Comment thread go/ql/lib/printCfg.ql Fixed
Comment thread go/ql/lib/printCfg.ql Fixed
Comment thread go/ql/lib/printCfg.ql Fixed
Comment thread go/ql/lib/semmle/go/controlflow/ControlFlowGraph.qll Fixed
Comment thread go/ql/lib/semmle/go/controlflow/ControlFlowGraph.qll Fixed
@owen-mc
owen-mc requested a review from aschackmull September 17, 2026 17:34
@owen-mc
owen-mc marked this pull request as ready for review September 17, 2026 17:35
@owen-mc
owen-mc requested review from a team as code owners September 17, 2026 17:35
Copilot AI balanced review requested due to automatic review settings September 17, 2026 17: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.

Copilot review overview

🟡 Changes recommended

The updated whitespace calculation can produce false positives for upgraded databases and whitespace inside parentheses.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced (auto)
Findings: 1 High severity

Note

Copilot is running an experiment and ran this review at Balanced.

Open (1)
What changed in this PR

Adds extraction and schema support for tracking parentheses around Go expressions and uses it in whitespace-precedence analysis.

Changes:

  • Records each expression’s parenthesis count.
  • Updates whitespace calculations to account for parentheses.
  • Adds upgrade/downgrade schemas and normalizes generated schema output.
File Description
go/​ql/​src/​InconsistentCode/​WhitespaceContradictsPrecedence.ql Uses parenthesis counts in whitespace analysis.
go/​ql/​lib/​upgrades/​d0e7336b491e35a4c890e0b9755a4030d32ee444/​upgrade.properties Defines the schema upgrade.
go/​ql/​lib/​upgrades/​d0e7336b491e35a4c890e0b9755a4030d32ee444/​old.dbscheme Captures the previous schema.
go/​ql/​lib/​upgrades/​d0e7336b491e35a4c890e0b9755a4030d32ee444/​go.dbscheme Captures the upgraded schema.
go/​ql/​lib/​go.dbscheme Adds the parenthesis relation.
go/​extractor/​extractor.go Counts and emits expression parentheses.
go/​extractor/​dbscheme/​tables.go Defines the new extraction table.
go/​extractor/​dbscheme/​dbscheme.go Normalizes generated schema trailing newlines.
go/​downgrades/​b4012cfa6fa7de1878c247155b7dfcd76df2604d/​upgrade.properties Defines removal of the relation.
go/​downgrades/​b4012cfa6fa7de1878c247155b7dfcd76df2604d/​old.dbscheme Captures the pre-downgrade schema.
go/​downgrades/​b4012cfa6fa7de1878c247155b7dfcd76df2604d/​go.dbscheme Captures the downgraded schema.

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

private int getNumberOfParentheses(Expr expr) {
isParenthesized(expr, result)
or
not isParenthesized(expr, _) and result = 0

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.

I accept this shortcoming for upgraded databases.

@owen-mc owen-mc added the no-change-note-required This PR does not need a change note label Sep 17, 2026

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

Looks plausible.

@owen-mc

owen-mc commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

DCA looks good: this gets rid of 3 FPs on one project and doesn't significantly affect performance.

@owen-mc
owen-mc merged commit dad94a7 into github:main Sep 18, 2026
23 of 24 checks passed
@owen-mc
owen-mc deleted the go/is-parenthesized branch September 18, 2026 13:15
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.

4 participants