authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-08 18:13:07-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-08 18:13:07-05:00
log57edd4dcb31eeaca69b93d2caf0e1f4eb3772e3e
tree83469f0155d232b2ab71b48b323bd50b8a37f734
parentfee875770cb8c9363219b736f6c03e15cff39b92

error sets - fix bad value for constant error literal


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
1230812308 if (!resolve_inferred_error_set(ira, child_type, field_ptr_instruction->base.source_node)) {
1230912309 return ira->codegen->builtin_types.entry_invalid;
1231012310 }
12311 ErrorTableEntry *err_entry = find_err_table_entry(child_type, field_name);
12311 err_entry = find_err_table_entry(child_type, field_name);
1231212312 if (err_entry == nullptr) {
1231312313 ir_add_error(ira, &field_ptr_instruction->base,
1231412314 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 {
108108 error.FileNotFound => unreachable,
109109 }
110110}
111
112
113test "explicit error set cast" {
114 testExplicitErrorSetCast(Set1.A);
115 comptime testExplicitErrorSetCast(Set1.A);
116}
117
118const Set1 = error{A, B};
119const Set2 = error{A, C};
120
121fn testExplicitErrorSetCast(set1: Set1) void {
122 var x = Set2(set1);
123 var y = Set1(x);
124 assert(y == error.A);
125}