Improve the recently-added PopulateSwitch tweak to work on non-empty switches.
Details
Diff Detail
Event Timeline
Very nice, thank you!
A few nits about comments and asserts.
clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp | ||
---|---|---|
112 | Somewhere we should have a high-level comment about what we're doing here: We trigger if there are fewer cases than enum values (and no case covers multiple values). | |
119 | Code is obvious here, say why instead? "Default likely intends to cover cases we'd insert."? (Sometimes this is still interesting in that case, so we could consider downgrading from "fix" to "refactoring" or so in this case. But it makes sense to be conservative for now) | |
123 | nit: just cast<CaseStmt> and don't check for null (it'll automatically assert). There are no other options. | |
127 | , so our counting argument doesn't work. | |
131 | "We may not be able to work out which cases are covered"? | |
152 | this can be an assert (and previous line a cast) - apply() never gets called unless prepare() returns true | |
156 | similarly here | |
183 | this is also an assert, right? I don't think we can get here. | |
clang-tools-extra/clangd/unittests/TweakTests.cpp | ||
2838 | is there an interesting difference between the single/multiple case that wouldn't be covered by just the multiple case? | |
2838 | can we add a case with default? |
- Improve comments
- In apply(), assert on the conditions we established in prepare() instead of proceeding.
- Remove redundant tests and add new ones for value-dependent and GNU range cases.
Somewhere we should have a high-level comment about what we're doing here:
We trigger if there are fewer cases than enum values (and no case covers multiple values).
This guarantees we'll have at least one case to insert.
We don't yet determine what the cases are, as that means evaluating expressions.