| ... | ... | @@ -233,11 +233,10 @@ static TypeTableEntry *get_error_type(CodeGen *g, TypeTableEntry *child_type) { |
| 233 | 233 | entry->data.error.child_type = child_type; |
| 234 | 234 | |
| 235 | 235 | if (child_type->size_in_bits == 0) { |
| 236 | | TypeTableEntry *tag_type = get_smallest_unsigned_int_type(g, g->next_error_index); |
| 237 | | entry->type_ref = tag_type->type_ref; |
| 238 | | entry->size_in_bits = tag_type->size_in_bits; |
| 239 | | entry->align_in_bits = tag_type->align_in_bits; |
| 240 | | entry->di_type = tag_type->di_type; |
| 236 | entry->type_ref = g->err_tag_type->type_ref; |
| 237 | entry->size_in_bits = g->err_tag_type->size_in_bits; |
| 238 | entry->align_in_bits = g->err_tag_type->align_in_bits; |
| 239 | entry->di_type = g->err_tag_type->di_type; |
| 241 | 240 | |
| 242 | 241 | } else { |
| 243 | 242 | zig_panic("TODO get_error_type non-void"); |
| ... | ... | @@ -2869,6 +2868,10 @@ static void eval_const_expr_implicit_cast(CodeGen *g, AstNode *node, AstNode *ex |
| 2869 | 2868 | const_val->data.x_maybe = other_val; |
| 2870 | 2869 | const_val->ok = true; |
| 2871 | 2870 | break; |
| 2871 | case CastOpErrToInt: |
| 2872 | bignum_init_unsigned(&const_val->data.x_bignum, other_val->data.x_err->value); |
| 2873 | const_val->ok = true; |
| 2874 | break; |
| 2872 | 2875 | } |
| 2873 | 2876 | } |
| 2874 | 2877 | |
| ... | ... | @@ -2975,6 +2978,24 @@ static TypeTableEntry *analyze_cast_expr(CodeGen *g, ImportTableEntry *import, B |
| 2975 | 2978 | } |
| 2976 | 2979 | } |
| 2977 | 2980 | |
| 2981 | // explicit cast from %void to integer type which can fit it |
| 2982 | if (actual_type->id == TypeTableEntryIdError && |
| 2983 | actual_type->data.error.child_type->size_in_bits == 0 && |
| 2984 | wanted_type->id == TypeTableEntryIdInt) |
| 2985 | { |
| 2986 | BigNum bn; |
| 2987 | bignum_init_unsigned(&bn, g->next_error_index); |
| 2988 | if (bignum_fits_in_bits(&bn, wanted_type->size_in_bits, wanted_type->data.integral.is_signed)) { |
| 2989 | node->data.fn_call_expr.cast_op = CastOpErrToInt; |
| 2990 | eval_const_expr_implicit_cast(g, node, expr_node); |
| 2991 | return wanted_type; |
| 2992 | } else { |
| 2993 | add_node_error(g, node, |
| 2994 | buf_sprintf("too many error values to fit in '%s'", buf_ptr(&wanted_type->name))); |
| 2995 | return g->builtin_types.entry_invalid; |
| 2996 | } |
| 2997 | } |
| 2998 | |
| 2978 | 2999 | add_node_error(g, node, |
| 2979 | 3000 | buf_sprintf("invalid cast from type '%s' to '%s'", |
| 2980 | 3001 | buf_ptr(&actual_type->name), |
| ... | ... | @@ -4353,6 +4374,9 @@ void semantic_analyze(CodeGen *g) { |
| 4353 | 4374 | } |
| 4354 | 4375 | } |
| 4355 | 4376 | } |
| 4377 | |
| 4378 | g->err_tag_type = get_smallest_unsigned_int_type(g, g->next_error_index); |
| 4379 | |
| 4356 | 4380 | { |
| 4357 | 4381 | auto it = g->import_table.entry_iterator(); |
| 4358 | 4382 | for (;;) { |