| author | |
| committer | |
| log | 57edd4dcb31eeaca69b93d2caf0e1f4eb3772e3e |
| tree | 83469f0155d232b2ab71b48b323bd50b8a37f734 |
| parent | fee875770cb8c9363219b736f6c03e15cff39b92 |
2 files changed, 16 insertions(+), 1 deletions(-)
src/ir.cpp+1-1| ... | ... | @@ -12308,7 +12308,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 12308 | 12308 | if (!resolve_inferred_error_set(ira, child_type, field_ptr_instruction->base.source_node)) { |
| 12309 | 12309 | return ira->codegen->builtin_types.entry_invalid; |
| 12310 | 12310 | } |
| 12311 | ErrorTableEntry *err_entry = find_err_table_entry(child_type, field_name); | |
| 12311 | err_entry = find_err_table_entry(child_type, field_name); | |
| 12312 | 12312 | if (err_entry == nullptr) { |
| 12313 | 12313 | ir_add_error(ira, &field_ptr_instruction->base, |
| 12314 | 12314 | buf_sprintf("no error named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&child_type->name))); |
test/cases/error.zig+15| ... | ... | @@ -108,3 +108,18 @@ fn testErrorSetType() void { |
| 108 | 108 | error.FileNotFound => unreachable, |
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | ||
| 112 | ||
| 113 | test "explicit error set cast" { | |
| 114 | testExplicitErrorSetCast(Set1.A); | |
| 115 | comptime testExplicitErrorSetCast(Set1.A); | |
| 116 | } | |
| 117 | ||
| 118 | const Set1 = error{A, B}; | |
| 119 | const Set2 = error{A, C}; | |
| 120 | ||
| 121 | fn testExplicitErrorSetCast(set1: Set1) void { | |
| 122 | var x = Set2(set1); | |
| 123 | var y = Set1(x); | |
| 124 | assert(y == error.A); | |
| 125 | } |