aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-03-14 11:55:29 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-03-14 11:57:56 -0400
commit080dd27157e79adc8e5d5b7c1dcf94919624abab (patch)
tree108c39a7f852c0b606bf2e8b2f6a6fecb7a8c2ee /src
parente861da03f9b9d1261cf32872ea942ee7a63812d3 (diff)
downloadzig-080dd27157e79adc8e5d5b7c1dcf94919624abab.tar.gz
zig-080dd27157e79adc8e5d5b7c1dcf94919624abab.zip
breaking: fix @typeInfo handling of global error set type
`builtin.TypeInfo.ErrorSet` is now `?[]Error` instead of `struct{errors:[]Error}`. closes #1936
Diffstat (limited to 'src')
-rw-r--r--src/codegen.cpp4
-rw-r--r--src/ir.cpp15
2 files changed, 6 insertions, 13 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 44e66c4dd8..df907915bb 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -7581,9 +7581,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
" value: comptime_int,\n"
" };\n"
"\n"
- " pub const ErrorSet = struct {\n"
- " errors: []Error,\n"
- " };\n"
+ " pub const ErrorSet = ?[]Error;\n"
"\n"
" pub const EnumField = struct {\n"
" name: []const u8,\n"
diff --git a/src/ir.cpp b/src/ir.cpp
index f138080f00..61be6670a5 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -18265,21 +18265,16 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
result->special = ConstValSpecialStatic;
result->type = ir_type_info_get_type(ira, "ErrorSet", nullptr);
- ConstExprValue *fields = create_const_vals(1);
- result->data.x_struct.fields = fields;
-
- // errors: []TypeInfo.Error
- ensure_field_index(result->type, "errors", 0);
-
ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr);
if (!resolve_inferred_error_set(ira->codegen, type_entry, source_instr->source_node)) {
return ErrorSemanticAnalyzeFail;
}
if (type_is_global_error_set(type_entry)) {
- ir_add_error(ira, source_instr,
- buf_sprintf("TODO: compiler bug: implement @typeInfo support for anyerror. https://github.com/ziglang/zig/issues/1936"));
- return ErrorSemanticAnalyzeFail;
+ result->data.x_optional = nullptr;
+ break;
}
+ ConstExprValue *slice_val = create_const_vals(1);
+ result->data.x_optional = slice_val;
uint32_t error_count = type_entry->data.error_set.err_count;
ConstExprValue *error_array = create_const_vals(1);
@@ -18288,7 +18283,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
error_array->data.x_array.special = ConstArraySpecialNone;
error_array->data.x_array.data.s_none.elements = create_const_vals(error_count);
- init_const_slice(ira->codegen, &fields[0], error_array, 0, error_count, false);
+ init_const_slice(ira->codegen, slice_val, error_array, 0, error_count, false);
for (uint32_t error_index = 0; error_index < error_count; error_index++) {
ErrorTableEntry *error = type_entry->data.error_set.errors[error_index];
ConstExprValue *error_val = &error_array->data.x_array.data.s_none.elements[error_index];