| author | |
| committer | |
| log | ac0cda8df81d5dc7d782ad8a32c0e5b064dd24ec |
| tree | d0eef967a9851bb83b8043ad6bb73dbb46ed8a00 |
| parent | 22e39e1e5ab42c2c3d33eeb6797f5835b2004fe3 |
| signature |
closes #15093 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) { | ... | @@ -4069,6 +4069,7 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) { |
| 4069 | } | 4069 | } |
| 4070 | 4070 | ||
| 4071 | bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node) { | 4071 | bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node) { |
| 4072 | assert(err_set_type->id == ZigTypeIdErrorSet); | ||
| 4072 | ZigFn *infer_fn = err_set_type->data.error_set.infer_fn; | 4073 | ZigFn *infer_fn = err_set_type->data.error_set.infer_fn; |
| 4073 | if (infer_fn != nullptr) { | 4074 | if (infer_fn != nullptr) { |
| 4074 | if (infer_fn->anal_state == FnAnalStateInvalid) { | 4075 | if (infer_fn->anal_state == FnAnalStateInvalid) { |
src/ir.cpp+12| ... | @@ -12469,10 +12469,22 @@ static ZigType *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -12469,10 +12469,22 @@ static ZigType *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp * |
| 12469 | if (type_is_invalid(op1_type)) | 12469 | if (type_is_invalid(op1_type)) |
| 12470 | return ira->codegen->builtin_types.entry_invalid; | 12470 | return ira->codegen->builtin_types.entry_invalid; |
| 12471 | 12471 | ||
| 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 | |||
| 12472 | ZigType *op2_type = ir_resolve_type(ira, instruction->op2->other); | 12478 | ZigType *op2_type = ir_resolve_type(ira, instruction->op2->other); |
| 12473 | if (type_is_invalid(op2_type)) | 12479 | if (type_is_invalid(op2_type)) |
| 12474 | return ira->codegen->builtin_types.entry_invalid; | 12480 | return ira->codegen->builtin_types.entry_invalid; |
| 12475 | 12481 | ||
| 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 | |||
| 12476 | if (type_is_global_error_set(op1_type) || | 12488 | if (type_is_global_error_set(op1_type) || |
| 12477 | type_is_global_error_set(op2_type)) | 12489 | type_is_global_error_set(op2_type)) |
| 12478 | { | 12490 | { |
test/compile_errors.zig+13| ... | @@ -1,6 +1,19 @@ | ... | @@ -1,6 +1,19 @@ |
| 1 | const tests = @import("tests.zig"); | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | ||
| 3 | pub fn addCases(cases: *tests.CompileErrorContext) void { | 3 | pub 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 | |||
| 4 | cases.add( | 17 | cases.add( |
| 5 | "variable initialization compile error then referenced", | 18 | "variable initialization compile error then referenced", |
| 6 | \\fn Undeclared() type { | 19 | \\fn Undeclared() type { |