From 57edd4dcb31eeaca69b93d2caf0e1f4eb3772e3e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 8 Feb 2018 18:13:07 -0500 Subject: [PATCH] error sets - fix bad value for constant error literal --- src/ir.cpp | 2 +- test/cases/error.zig | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ir.cpp b/src/ir.cpp index 25723535dd..728a3e815c 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -12308,7 +12308,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru if (!resolve_inferred_error_set(ira, child_type, field_ptr_instruction->base.source_node)) { return ira->codegen->builtin_types.entry_invalid; } - ErrorTableEntry *err_entry = find_err_table_entry(child_type, field_name); + err_entry = find_err_table_entry(child_type, field_name); if (err_entry == nullptr) { ir_add_error(ira, &field_ptr_instruction->base, buf_sprintf("no error named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&child_type->name))); diff --git a/test/cases/error.zig b/test/cases/error.zig index 0322cb9246..3d2835e723 100644 --- a/test/cases/error.zig +++ b/test/cases/error.zig @@ -108,3 +108,18 @@ fn testErrorSetType() void { error.FileNotFound => unreachable, } } + + +test "explicit error set cast" { + testExplicitErrorSetCast(Set1.A); + comptime testExplicitErrorSetCast(Set1.A); +} + +const Set1 = error{A, B}; +const Set2 = error{A, C}; + +fn testExplicitErrorSetCast(set1: Set1) void { + var x = Set2(set1); + var y = Set1(x); + assert(y == error.A); +}