| ... | ... | @@ -4241,6 +4241,8 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry |
| 4241 | 4241 | return resolve_expr_const_val_as_bool(g, node, g->is_release_build, true); |
| 4242 | 4242 | } else if (buf_eql_str(&var_name, "is_test")) { |
| 4243 | 4243 | return resolve_expr_const_val_as_bool(g, node, g->is_test_build, true); |
| 4244 | } else if (buf_eql_str(&var_name, "os")) { |
| 4245 | zig_panic("TODO"); |
| 4244 | 4246 | } else { |
| 4245 | 4247 | add_node_error(g, *str_node, |
| 4246 | 4248 | buf_sprintf("unrecognized compile variable: '%s'", buf_ptr(&var_name))); |
| ... | ... | @@ -4650,6 +4652,11 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import, |
| 4650 | 4652 | buf_sprintf("switch on unreachable expression not allowed")); |
| 4651 | 4653 | return g->builtin_types.entry_invalid; |
| 4652 | 4654 | } else { |
| 4655 | int *field_use_counts = nullptr; |
| 4656 | if (expr_type->id == TypeTableEntryIdEnum) { |
| 4657 | field_use_counts = allocate<int>(expr_type->data.enumeration.field_count); |
| 4658 | } |
| 4659 | |
| 4653 | 4660 | AstNode *else_prong = nullptr; |
| 4654 | 4661 | for (int prong_i = 0; prong_i < prong_count; prong_i += 1) { |
| 4655 | 4662 | AstNode *prong_node = node->data.switch_expr.prongs.at(prong_i); |
| ... | ... | @@ -4686,6 +4693,14 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import, |
| 4686 | 4693 | if (type_enum_field->type_entry != var_type) { |
| 4687 | 4694 | all_agree_on_var_type = false; |
| 4688 | 4695 | } |
| 4696 | uint32_t field_index = type_enum_field->value; |
| 4697 | assert(field_use_counts); |
| 4698 | field_use_counts[field_index] += 1; |
| 4699 | if (field_use_counts[field_index] > 1) { |
| 4700 | add_node_error(g, item_node, |
| 4701 | buf_sprintf("duplicate switch value: '%s'", |
| 4702 | buf_ptr(type_enum_field->name))); |
| 4703 | } |
| 4689 | 4704 | } else { |
| 4690 | 4705 | add_node_error(g, item_node, |
| 4691 | 4706 | buf_sprintf("enum '%s' has no field '%s'", |
| ... | ... | @@ -4729,6 +4744,16 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import, |
| 4729 | 4744 | prong_node->data.switch_prong.expr); |
| 4730 | 4745 | peer_nodes[prong_i] = prong_node->data.switch_prong.expr; |
| 4731 | 4746 | } |
| 4747 | |
| 4748 | if (expr_type->id == TypeTableEntryIdEnum && !else_prong) { |
| 4749 | for (uint32_t i = 0; i < expr_type->data.enumeration.field_count; i += 1) { |
| 4750 | if (field_use_counts[i] == 0) { |
| 4751 | add_node_error(g, node, |
| 4752 | buf_sprintf("enumeration value '%s' not handled in switch", |
| 4753 | buf_ptr(expr_type->data.enumeration.fields[i].name))); |
| 4754 | } |
| 4755 | } |
| 4756 | } |
| 4732 | 4757 | } |
| 4733 | 4758 | return resolve_peer_type_compatibility(g, import, context, node, peer_nodes, peer_types, prong_count); |
| 4734 | 4759 | } |