Skip to content

Warn when a synchronized loop never ends - #167

Closed
virzak wants to merge 2 commits into
masterfrom
feature/endless-loop-warning
Closed

virzak wants to merge 2 commits into
masterfrom
feature/endless-loop-warning

Conversation

@virzak

@virzak virzak commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Supersedes #69 by @GerardSmit, reworked for current master.

A while (!ct.IsCancellationRequested) loop becomes while (true) once synchronized. When nothing else leaves it (break, return, throw, yield break, goto, or a [DoesNotReturn] call) the generator now reports ZSMGEN006, and statements after a loop no break leaves are dropped, since they're unreachable (CS0162).

Generated with Claude Code

virzak and others added 2 commits September 12, 2026 11:00
A while loop on !ct.IsCancellationRequested becomes while (true) in the
synchronized version. Unless something else leaves the loop it never
ends, and the statements after it can't be reached, which the compiler
reports as CS0162 in the generated file.

Generated with Claude Code
A cancellation check in a while loop's condition becomes true once
synchronized. When nothing else leaves the loop - a break belonging to
it, a return, throw, yield break, goto, or a call to a [DoesNotReturn]
method - report ZSMGEN006. When no break leaves it, drop the
statements after it too, since they can't be reached.

The loop is judged on its rewritten body, because the rewrite also
drops checks such as if (ct.IsCancellationRequested) break;. Based
on #69.

Generated with Claude Code

Co-authored-by: Gerard Smit <gsmit1996@gmail.com>
@codecov

codecov Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.40741% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.28%. Comparing base (ed21fb7) to head (c39be85).

Files with missing lines Patch % Lines
...Zomp.SyncMethodGenerator/Helpers/LoopExitWalker.cs 32.25% 19 Missing and 2 partials ⚠️
...rc/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs 87.50% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #167      +/-   ##
==========================================
- Coverage   93.47%   92.28%   -1.19%     
==========================================
  Files          10       11       +1     
  Lines        1593     1647      +54     
  Branches      374      380       +6     
==========================================
+ Hits         1489     1520      +31     
- Misses         26       45      +19     
- Partials       78       82       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@virzak

virzak commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

Moved into #69 so the commit stays Gerard's.

@virzak virzak closed this Sep 12, 2026
@virzak
virzak deleted the feature/endless-loop-warning branch September 12, 2026 15:17
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