Skip to content

Commit

Permalink
Use a switch in StringifyTypeExpr
Browse files Browse the repository at this point in the history
Get a compiler error when a case isn't handled instead of a runtime
CHECK failure.

Error confirmed locally, it looks like:
```
toolchain/sem_ir/stringify_type.cpp:120:13: error: enumeration value 'Name' not handled in switch [-Werror,-Wswitch]
  120 |     switch (step.kind) {
      |             ^~~~~~~~~
1 error generated.
```
  • Loading branch information
danakj committed Nov 27, 2024
1 parent b894d4e commit 453059a
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions toolchain/sem_ir/stringify_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,22 @@ auto StringifyTypeExpr(const SemIR::File& sem_ir, InstId outer_inst_id)
while (!step_stack.empty()) {
auto step = step_stack.Pop();

if (step.kind == StepStack::FixedString) {
out << step.fixed_string;
continue;
}
if (step.kind == StepStack::ArrayBound) {
out << sem_ir.GetArrayBoundValue(step.bound_id);
continue;
}
if (step.kind == StepStack::Name) {
out << sem_ir.names().GetFormatted(step.name_id);
continue;
}
CARBON_CHECK(step.kind == StepStack::Inst);
if (!step.inst_id.is_valid()) {
out << "<invalid type>";
continue;
switch (step.kind) {
case StepStack::FixedString:
out << step.fixed_string;
continue;
case StepStack::ArrayBound:
out << sem_ir.GetArrayBoundValue(step.bound_id);
continue;
case StepStack::Name:
out << sem_ir.names().GetFormatted(step.name_id);
continue;
case StepStack::Inst:
if (!step.inst_id.is_valid()) {
out << "<invalid type>";
continue;
}
// Fall through to the rest of the function.
}

auto untyped_inst = sem_ir.insts().Get(step.inst_id);
Expand Down

0 comments on commit 453059a

Please sign in to comment.