| ... | ... | @@ -1789,6 +1789,24 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: |
| 1789 | 1789 | }); |
| 1790 | 1790 | } |
| 1791 | 1791 | |
| 1792 | fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazySrcLoc, container_ty: Type, field_index: usize) CompileError { |
| 1793 | const msg = msg: { |
| 1794 | const msg = try sema.errMsg(block, init_src, "value stored in comptime field does not match the default value of the field", .{}); |
| 1795 | errdefer msg.destroy(sema.gpa); |
| 1796 | |
| 1797 | const decl_index = container_ty.getOwnerDeclOrNull() orelse break :msg msg; |
| 1798 | |
| 1799 | const tree = try sema.getAstTree(block); |
| 1800 | const decl = sema.mod.declPtr(decl_index); |
| 1801 | const field_src = enumFieldSrcLoc(decl, tree.*, container_ty.getNodeOffset(), field_index); |
| 1802 | const default_value_src: LazySrcLoc = .{ .node_offset_field_default = field_src.node_offset.x }; |
| 1803 | |
| 1804 | try sema.errNote(block, default_value_src, msg, "default value set here", .{}); |
| 1805 | break :msg msg; |
| 1806 | }; |
| 1807 | return sema.failWithOwnedErrorMsg(block, msg); |
| 1808 | } |
| 1809 | |
| 1792 | 1810 | /// We don't return a pointer to the new error note because the pointer |
| 1793 | 1811 | /// becomes invalid when you add another one. |
| 1794 | 1812 | fn errNote( |
| ... | ... | @@ -14542,8 +14560,7 @@ fn zirStructInit( |
| 14542 | 14560 | }; |
| 14543 | 14561 | |
| 14544 | 14562 | if (!init_val.eql(default_value, resolved_ty.structFieldType(field_index), sema.mod)) { |
| 14545 | | // TODO add note showing where default value is provided |
| 14546 | | return sema.fail(block, field_src, "value stored in comptime field does not match the default value of the field", .{}); |
| 14563 | return sema.failWithInvalidComptimeFieldStore(block, field_src, resolved_ty, field_index); |
| 14547 | 14564 | } |
| 14548 | 14565 | }; |
| 14549 | 14566 | } |
| ... | ... | @@ -22379,7 +22396,7 @@ fn storePtrVal( |
| 22379 | 22396 | .direct => |val_ptr| { |
| 22380 | 22397 | if (mut_kit.decl_ref_mut.runtime_index == .comptime_field_ptr) { |
| 22381 | 22398 | if (!operand_val.eql(val_ptr.*, operand_ty, sema.mod)) { |
| 22382 | | // TODO add note showing where default value is provided |
| 22399 | // TODO use failWithInvalidComptimeFieldStore |
| 22383 | 22400 | return sema.fail(block, src, "value stored in comptime field does not match the default value of the field", .{}); |
| 22384 | 22401 | } |
| 22385 | 22402 | return; |
| ... | ... | @@ -23754,8 +23771,7 @@ fn coerceTupleToStruct( |
| 23754 | 23771 | }; |
| 23755 | 23772 | |
| 23756 | 23773 | if (!init_val.eql(field.default_val, field.ty, sema.mod)) { |
| 23757 | | // TODO add note showing where default value is provided |
| 23758 | | return sema.fail(block, field_src, "value stored in comptime field does not match the default value of the field", .{}); |
| 23774 | return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, i); |
| 23759 | 23775 | } |
| 23760 | 23776 | } |
| 23761 | 23777 | if (runtime_src == null) { |