fix(loc): C# drops a declaration under a brace-less for body from lloc
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust
- Domain
- testing-qa
Research direction
Start with src/metrics/loc/csharp.rs and inspect the local_declaration_statement ancestor walk that skips declarations beneath a for. Compare its behavior with the JavaScript family fix referenced as #1283. Add a C# regression test for the reported brace-less for and switch input, then confirm lloc is 4 and remains 4 when braces surround the for body.
Written by the indexing model from the issue text.
Description
A declaration that is the unbraced body of a for, or sits under one with no block between, is dropped from lloc in C#.
Reproduction
Inside class A { void F() { … } }, values are lloc of the unit.
| Input | Expected | Actual |
|---|---|---|
for (int i = 0; i < 2; i++) switch (i) { case 0: int y = 1; break; } |
4 (for, switch, the declaration, break) |
3 |
the same with braces around the for body |
4 | 4 |
Cause
src/metrics/loc/csharp.rs skips a local_declaration_statement whose ancestor walk reaches a for before a block, to keep a for header's declaration from counting as a statement. In tree-sitter-c-sharp 0.23.5 a for initializer is a variable_declaration, never a local_declaration_statement, so the gate cannot fire for a header. It fires only for a declaration in the for body with no block between, where it drops a real statement.
This is the miss #1283 fixed for the JS family (js_family_braceless_for_body_declaration_counts). The same brace-less switch shape in Java also read 3; not investigated further.
Why it is filed from #1736
The escaped mutant replace == with != in <impl Loc for CsharpCode>::compute on that gate differs from the original only on inputs like the first row, where the original undercounts and the mutant reads 4. A test that kills it would pin the wrong value. It stays open on #1736 until this is fixed.
- Dominant language
- Rust
- Stars
- 32
- Forks
- 3
- Avg merge
- 9h 55m
- Merged PRs (30d)
- 102
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dekobon/big-code-analysis
-
documentation low-priority
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dekobon/big-code-analysis#1883 ·
Maintainers usually reply within 1 day
-
low-priority performance
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dekobon/big-code-analysis#1879 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
dekobon/big-code-analysis#1458 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
dekobon/big-code-analysis#1444 ·
Maintainers usually reply within 1 day
-
security upstream-grammar
Difficulty 2/5 Under an hour Newbie friendliness 75/100
dekobon/big-code-analysis#1058 · 3 comments ·
Maintainers usually reply within 1 day
All issues in dekobon/big-code-analysis
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ElectronicWave/Elemental#252 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
area:mcp effort:low P5 source:agent
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
jlcodes99/cockpit-tools#3103 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
eliasstravik/herdr-projects#1032 ·