Skip to content

Commit

Permalink
Remove default case where possible to get compile errors instead
Browse files Browse the repository at this point in the history
Summary: Removing the `default` case when we expect to handle each enum variant so that we'll get compile time type errors when updating enums.

Reviewed By: arthaud

Differential Revision: D47534915

fbshipit-source-id: 75be4ab16267340e0c5e153ce59dc6b287617811
  • Loading branch information
Anwesh Tuladhar authored and facebook-github-bot committed Jul 19, 2023
1 parent 5b44c7b commit ebcc528
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
8 changes: 4 additions & 4 deletions source/Access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,9 @@ std::string PathElement::to_string() const {
case PathElement::Kind::IndexFromValueOf:
return fmt::format(
"[<{}>]", Root(Root::Kind::Argument, parameter_position()));

default:
mt_unreachable();
}

mt_unreachable();
}

PathElement PathElement::from_json(const Json::Value& value) {
Expand Down Expand Up @@ -273,9 +272,10 @@ std::string Root::to_string() const {
return "call-chain";
case Root::Kind::CallEffectIntent:
return "call-effect-intent";
default:
case Root::Kind::MaxArgument:
mt_unreachable();
}
mt_unreachable();
}

Json::Value Root::to_json() const {
Expand Down
3 changes: 1 addition & 2 deletions source/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ std::string model_mode_to_string(Model::Mode mode) {
return "alias-memory-location-on-invoke";
case Model::Mode::StrongWriteOnPropagation:
return "strong-write-on-propagation";
default:
mt_unreachable();
}
mt_unreachable();
}

std::optional<Model::Mode> string_to_model_mode(const std::string& mode) {
Expand Down
5 changes: 1 addition & 4 deletions source/constraints/IntegerConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ bool IntegerConstraint::satisfy(int lhs) const {
case Operator::EQ: {
return lhs == rhs_;
}
default: {
mt_unreachable();
return true;
}
}
mt_unreachable();
}

bool IntegerConstraint::operator==(const IntegerConstraint& other) const {
Expand Down
6 changes: 2 additions & 4 deletions source/constraints/TypeConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ MethodHashedSet TypePatternConstraint::may_satisfy(
case MaySatisfyMethodConstraintKind::Extends:
return method_mappings.class_to_override_methods().get(
*string_pattern, MethodHashedSet::bottom());
default:
mt_unreachable();
}
mt_unreachable();
}

bool TypePatternConstraint::satisfy(const DexType* type) const {
Expand Down Expand Up @@ -67,9 +66,8 @@ MethodHashedSet TypeNameConstraint::may_satisfy(
case MaySatisfyMethodConstraintKind::Extends:
return method_mappings.class_to_override_methods().get(
name_, MethodHashedSet::bottom());
default:
mt_unreachable();
}
mt_unreachable();
}

bool TypeNameConstraint::satisfy(const DexType* type) const {
Expand Down

0 comments on commit ebcc528

Please sign in to comment.