authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-13 13:48:41-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-13 13:48:41-04:00
logac0cda8df81d5dc7d782ad8a32c0e5b064dd24ec
treed0eef967a9851bb83b8043ad6bb73dbb46ed8a00
parent22e39e1e5ab42c2c3d33eeb6797f5835b2004fe3
signaturelock-open Commit is signed but in an unrecognized format.

add compile error for merging non- error sets

closes #1509

3 files changed, 26 insertions(+), 0 deletions(-)

src/analyze.cpp+1
......@@ -4069,6 +4069,7 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
40694069}
40704070
40714071bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node) {
4072 assert(err_set_type->id == ZigTypeIdErrorSet);
40724073 ZigFn *infer_fn = err_set_type->data.error_set.infer_fn;
40734074 if (infer_fn != nullptr) {
40744075 if (infer_fn->anal_state == FnAnalStateInvalid) {
src/ir.cpp+12
......@@ -12469,10 +12469,22 @@ static ZigType *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *
1246912469 if (type_is_invalid(op1_type))
1247012470 return ira->codegen->builtin_types.entry_invalid;
1247112471
12472 if (op1_type->id != ZigTypeIdErrorSet) {
12473 ir_add_error(ira, instruction->op1,
12474 buf_sprintf("expected error set type, found '%s'", buf_ptr(&op1_type->name)));
12475 return ira->codegen->builtin_types.entry_invalid;
12476 }
12477
1247212478 ZigType *op2_type = ir_resolve_type(ira, instruction->op2->other);
1247312479 if (type_is_invalid(op2_type))
1247412480 return ira->codegen->builtin_types.entry_invalid;
1247512481
12482 if (op2_type->id != ZigTypeIdErrorSet) {
12483 ir_add_error(ira, instruction->op2,
12484 buf_sprintf("expected error set type, found '%s'", buf_ptr(&op2_type->name)));
12485 return ira->codegen->builtin_types.entry_invalid;
12486 }
12487
1247612488 if (type_is_global_error_set(op1_type) ||
1247712489 type_is_global_error_set(op2_type))
1247812490 {
test/compile_errors.zig+13
......@@ -1,6 +1,19 @@
11const tests = @import("tests.zig");
22
33pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "non error sets used in merge error sets operator",
6 \\export fn foo() void {
7 \\ const Errors = u8 || u16;
8 \\}
9 \\export fn bar() void {
10 \\ const Errors = error{} || u16;
11 \\}
12 ,
13 ".tmp_source.zig:2:20: error: expected error set type, found 'u8'",
14 ".tmp_source.zig:5:31: error: expected error set type, found 'u16'",
15 );
16
417 cases.add(
518 "variable initialization compile error then referenced",
619 \\fn Undeclared() type {