Skip to content

fix: bind using directly to constructed TestConsole (cs/local-not-disposed) - #16

Merged
StuartMeeks merged 1 commit into
mainfrom
fix/codeql-testconsole-dispose
Aug 22, 2026
Merged

fix: bind using directly to constructed TestConsole (cs/local-not-disposed)#16
StuartMeeks merged 1 commit into
mainfrom
fix/codeql-testconsole-dispose

Conversation

@StuartMeeks

Copy link
Copy Markdown
Owner

What

Follow-up to #15. When CodeQL switched to build-mode: none, it reopened cs/local-not-disposed on the Width(120) test (now alert #5).

using var test = new TestConsole().Width(120); binds the using to the return value of Width(). CodeQL can't prove a fluent method returns its own receiver, so it treated the new TestConsole() as a disposable that never reaches a using. Splitting the fluent call onto its own statement makes the using bind directly to the constructed console:

using var test = new TestConsole();
test.Width(120);

TestConsole.Width mutates in place and returns this, so discarding the return value is equivalent — behaviour-preserving.

Verification

🤖 Generated with Claude Code

…posed)

The build-mode: none CodeQL run reopened cs/local-not-disposed on the
Width(120) test: `using var test = new TestConsole().Width(120)` binds the
using to Width()'s return value, and CodeQL cannot prove a fluent method
returns its receiver, so it saw the `new TestConsole()` as an undisposed
disposable. Split the fluent call onto its own statement so the using binds
directly to the construction. Behaviour-preserving; 80/80 tests pass on both TFMs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@StuartMeeks
StuartMeeks merged commit 18b36a6 into main Aug 22, 2026
9 checks passed
@StuartMeeks
StuartMeeks deleted the fix/codeql-testconsole-dispose branch August 22, 2026 02:24
@StuartMeeks StuartMeeks mentioned this pull request Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant