control-flow/missing-return.test \
control-flow/nested-conditional.vala \
control-flow/switch.vala \
+ control-flow/switch-enum.vala \
control-flow/sideeffects.vala \
control-flow/unassigned-captured-local-variable.test \
control-flow/unassigned-local-block-variable.test \
handle_errors (stmt.expression);
bool has_default_label = false;
+ bool is_enum_typed = stmt.expression.value_type is EnumValueType;
+
+ unowned Enum? en = null;
+ HashSet<unowned EnumValue>? enum_values = null;
+ if (is_enum_typed) {
+ en = (Enum) ((EnumValueType) stmt.expression.value_type).type_symbol;
+ enum_values = new HashSet<unowned EnumValue> (direct_hash, direct_equal);
+ }
foreach (SwitchSection section in stmt.get_sections ()) {
current_block = new BasicBlock ();
section_stmt.accept (this);
}
+ if (is_enum_typed) {
+ foreach (SwitchLabel label in section.get_labels ()) {
+ if (label.expression != null) {
+ unowned EnumValue? val = label.expression.symbol_reference as EnumValue;
+ if (val != null) {
+ enum_values.add (val);
+ }
+ }
+ }
+ }
+
if (section.has_default_label ()) {
has_default_label = true;
}
}
}
+ if (is_enum_typed) {
+ // Check if enum-based switching as fully covered, and if so,
+ // handle it like there was a default-label given
+
+ HashSet<EnumValue> remaining_values = new HashSet<EnumValue> ();
+ remaining_values.add_all (en.get_values ());
+ foreach (var val in enum_values) {
+ remaining_values.remove (val);
+ }
+ if (remaining_values.size == 0) {
+ has_default_label = true;
+ } else if (!has_default_label) {
+ string[] missing_vals = {};
+ foreach (var val in remaining_values) {
+ missing_vals += val.name;
+ }
+ Report.warning (stmt.source_reference, "switch does not handle `%s' of enum `%s'".printf (string.joinv ("', `", missing_vals), en.get_full_name ()));
+ }
+ }
+
if (!has_default_label) {
condition_block.connect (after_switch_block);
}