| ... | @@ -17484,9 +17484,15 @@ fn unionFieldVal( | ... | @@ -17484,9 +17484,15 @@ fn unionFieldVal( |
| 17484 | if (tag_matches) { | 17484 | if (tag_matches) { |
| 17485 | return sema.addConstant(field.ty, tag_and_val.val); | 17485 | return sema.addConstant(field.ty, tag_and_val.val); |
| 17486 | } else { | 17486 | } else { |
| 17487 | // TODO enhance this saying which one was active | 17487 | const msg = msg: { |
| 17488 | // and which one was accessed, and showing where the union was declared. | 17488 | const active_index = tag_and_val.tag.castTag(.enum_field_index).?.data; |
| 17489 | return sema.fail(block, src, "access of inactive union field", .{}); | 17489 | const active_field_name = union_obj.fields.keys()[active_index]; |
| | 17490 | const msg = try sema.errMsg(block, src, "access of union field '{s}' while field '{s}' is active", .{ field_name, active_field_name }); |
| | 17491 | errdefer msg.destroy(sema.gpa); |
| | 17492 | try sema.addDeclaredHereNote(msg, union_ty); |
| | 17493 | break :msg msg; |
| | 17494 | }; |
| | 17495 | return sema.failWithOwnedErrorMsg(block, msg); |
| 17490 | } | 17496 | } |
| 17491 | }, | 17497 | }, |
| 17492 | .Packed, .Extern => { | 17498 | .Packed, .Extern => { |