Improve the recently-added PopulateSwitch tweak to work on non-empty switches.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Very nice, thank you!
A few nits about comments and asserts.
clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp | ||
---|---|---|
113–129 | 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). | |
120 | 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) | |
124 | nit: just cast<CaseStmt> and don't check for null (it'll automatically assert). There are no other options. | |
128 | , so our counting argument doesn't work. | |
132 | "We may not be able to work out which cases are covered"? | |
153 | this can be an assert (and previous line a cast) - apply() never gets called unless prepare() returns true | |
157 | similarly here | |
180 | 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.
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)