| author | |
| committer | |
| log | 3306e43984a8b17472ecc4b13a2f2815d6630eef |
| tree | 02a0a482a9887c5d439d0e2ec3e442da58a3f89c |
| parent | da9d8a6ecfb0428ce3d6575905f96fa1661c9b80 |
| signature |
See #6832 files changed, 17 insertions(+), 1 deletions(-)
src/ir.cpp+3-1| ... | ... | @@ -11601,8 +11601,10 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 11601 | 11601 | |
| 11602 | 11602 | TypeEnumField *field = find_enum_type_field(wanted_type, value->value.data.x_enum_literal); |
| 11603 | 11603 | if (field == nullptr) { |
| 11604 | ir_add_error(ira, source_instr, buf_sprintf("enum '%s' has no field named '%s'", | |
| 11604 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("enum '%s' has no field named '%s'", | |
| 11605 | 11605 | buf_ptr(&wanted_type->name), buf_ptr(value->value.data.x_enum_literal))); |
| 11606 | add_error_note(ira->codegen, msg, wanted_type->data.enumeration.decl_node, | |
| 11607 | buf_sprintf("'%s' declared here", buf_ptr(&wanted_type->name))); | |
| 11606 | 11608 | return ira->codegen->invalid_instruction; |
| 11607 | 11609 | } |
| 11608 | 11610 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
test/compile_errors.zig+14| ... | ... | @@ -2,6 +2,20 @@ const tests = @import("tests.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | |
| 4 | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.add( | |
| 6 | "cast enum literal to enum but it doesn't match", | |
| 7 | \\const Foo = enum { | |
| 8 | \\ a, | |
| 9 | \\ b, | |
| 10 | \\}; | |
| 11 | \\export fn entry() void { | |
| 12 | \\ const x: Foo = .c; | |
| 13 | \\} | |
| 14 | , | |
| 15 | "tmp.zig:6:20: error: enum 'Foo' has no field named 'c'", | |
| 16 | "tmp.zig:1:13: note: 'Foo' declared here", | |
| 17 | ); | |
| 18 | ||
| 5 | 19 | cases.add( |
| 6 | 20 | "discarding error value", |
| 7 | 21 | \\export fn entry() void { |