| ... | ... | @@ -74,6 +74,8 @@ types_to_resolve: std.ArrayListUnmanaged(Air.Inst.Ref) = .{}, |
| 74 | 74 | /// Sema must convert comptime control flow to runtime control flow, which means |
| 75 | 75 | /// breaking from a block. |
| 76 | 76 | post_hoc_blocks: std.AutoHashMapUnmanaged(Air.Inst.Index, *LabeledBlock) = .{}, |
| 77 | /// Populated with the last compile error created. |
| 78 | err: ?*Module.ErrorMsg = null, |
| 77 | 79 | |
| 78 | 80 | const std = @import("std"); |
| 79 | 81 | const mem = std.mem; |
| ... | ... | @@ -174,7 +176,6 @@ pub const Block = struct { |
| 174 | 176 | pub const Inlining = struct { |
| 175 | 177 | comptime_result: Air.Inst.Ref, |
| 176 | 178 | merges: Merges, |
| 177 | | err: ?*Module.ErrorMsg = null, |
| 178 | 179 | }; |
| 179 | 180 | |
| 180 | 181 | pub const Merges = struct { |
| ... | ... | @@ -1159,7 +1160,7 @@ fn analyzeBodyInner( |
| 1159 | 1160 | try sema.errNote(block, runtime_src, msg, "runtime control flow here", .{}); |
| 1160 | 1161 | break :msg msg; |
| 1161 | 1162 | }; |
| 1162 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 1163 | return sema.failWithOwnedErrorMsg(msg); |
| 1163 | 1164 | } |
| 1164 | 1165 | } |
| 1165 | 1166 | i += 1; |
| ... | ... | @@ -1738,7 +1739,7 @@ fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: [ |
| 1738 | 1739 | try sema.errNote(block, src, msg, "{s}", .{reason}); |
| 1739 | 1740 | break :msg msg; |
| 1740 | 1741 | }; |
| 1741 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 1742 | return sema.failWithOwnedErrorMsg(msg); |
| 1742 | 1743 | } |
| 1743 | 1744 | |
| 1744 | 1745 | fn failWithUseOfUndef(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { |
| ... | ... | @@ -1770,7 +1771,7 @@ fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty |
| 1770 | 1771 | } |
| 1771 | 1772 | break :msg msg; |
| 1772 | 1773 | }; |
| 1773 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 1774 | return sema.failWithOwnedErrorMsg(msg); |
| 1774 | 1775 | } |
| 1775 | 1776 | |
| 1776 | 1777 | fn failWithStructInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError { |
| ... | ... | @@ -1801,7 +1802,7 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: |
| 1801 | 1802 | try sema.errNote(block, src, msg, "when computing vector element at index '{d}'", .{vector_index}); |
| 1802 | 1803 | break :msg msg; |
| 1803 | 1804 | }; |
| 1804 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 1805 | return sema.failWithOwnedErrorMsg(msg); |
| 1805 | 1806 | } |
| 1806 | 1807 | return sema.fail(block, src, "overflow of integer type '{}' with value '{}'", .{ |
| 1807 | 1808 | int_ty.fmt(sema.mod), val.fmtValue(int_ty, sema.mod), |
| ... | ... | @@ -1823,7 +1824,7 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS |
| 1823 | 1824 | try sema.errNote(block, default_value_src, msg, "default value set here", .{}); |
| 1824 | 1825 | break :msg msg; |
| 1825 | 1826 | }; |
| 1826 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 1827 | return sema.failWithOwnedErrorMsg(msg); |
| 1827 | 1828 | } |
| 1828 | 1829 | |
| 1829 | 1830 | /// We don't return a pointer to the new error note because the pointer |
| ... | ... | @@ -1878,10 +1879,10 @@ pub fn fail( |
| 1878 | 1879 | args: anytype, |
| 1879 | 1880 | ) CompileError { |
| 1880 | 1881 | const err_msg = try sema.errMsg(block, src, format, args); |
| 1881 | | return sema.failWithOwnedErrorMsg(block, err_msg); |
| 1882 | return sema.failWithOwnedErrorMsg(err_msg); |
| 1882 | 1883 | } |
| 1883 | 1884 | |
| 1884 | | fn failWithOwnedErrorMsg(sema: *Sema, block: *Block, err_msg: *Module.ErrorMsg) CompileError { |
| 1885 | fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { |
| 1885 | 1886 | @setCold(true); |
| 1886 | 1887 | |
| 1887 | 1888 | if (crash_report.is_enabled and sema.mod.comp.debug_compile_errors) { |
| ... | ... | @@ -1894,7 +1895,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, block: *Block, err_msg: *Module.ErrorMsg) |
| 1894 | 1895 | } |
| 1895 | 1896 | |
| 1896 | 1897 | const mod = sema.mod; |
| 1897 | | if (block.inlining) |some| some.err = err_msg; |
| 1898 | sema.err = err_msg; |
| 1898 | 1899 | |
| 1899 | 1900 | { |
| 1900 | 1901 | errdefer err_msg.destroy(mod.gpa); |
| ... | ... | @@ -2591,7 +2592,7 @@ fn zirEnumDecl( |
| 2591 | 2592 | try sema.errNote(block, other_tag_src, msg, "other field here", .{}); |
| 2592 | 2593 | break :msg msg; |
| 2593 | 2594 | }; |
| 2594 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 2595 | return sema.failWithOwnedErrorMsg(msg); |
| 2595 | 2596 | } |
| 2596 | 2597 | |
| 2597 | 2598 | if (has_tag_value) { |
| ... | ... | @@ -2886,7 +2887,7 @@ fn ensureResultUsed( |
| 2886 | 2887 | try sema.errNote(block, src, msg, "consider using `try`, `catch`, or `if`", .{}); |
| 2887 | 2888 | break :msg msg; |
| 2888 | 2889 | }; |
| 2889 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 2890 | return sema.failWithOwnedErrorMsg(msg); |
| 2890 | 2891 | }, |
| 2891 | 2892 | else => { |
| 2892 | 2893 | const msg = msg: { |
| ... | ... | @@ -2896,7 +2897,7 @@ fn ensureResultUsed( |
| 2896 | 2897 | try sema.errNote(block, src, msg, "this error can be suppressed by assigning the value to '_'", .{}); |
| 2897 | 2898 | break :msg msg; |
| 2898 | 2899 | }; |
| 2899 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 2900 | return sema.failWithOwnedErrorMsg(msg); |
| 2900 | 2901 | }, |
| 2901 | 2902 | } |
| 2902 | 2903 | } |
| ... | ... | @@ -2917,7 +2918,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 2917 | 2918 | try sema.errNote(block, src, msg, "consider using `try`, `catch`, or `if`", .{}); |
| 2918 | 2919 | break :msg msg; |
| 2919 | 2920 | }; |
| 2920 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 2921 | return sema.failWithOwnedErrorMsg(msg); |
| 2921 | 2922 | }, |
| 2922 | 2923 | else => return, |
| 2923 | 2924 | } |
| ... | ... | @@ -2957,7 +2958,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 2957 | 2958 | ); |
| 2958 | 2959 | break :msg msg; |
| 2959 | 2960 | }; |
| 2960 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 2961 | return sema.failWithOwnedErrorMsg(msg); |
| 2961 | 2962 | } |
| 2962 | 2963 | |
| 2963 | 2964 | return sema.fieldVal(block, src, object, "len", src); |
| ... | ... | @@ -3615,7 +3616,7 @@ fn validateUnionInit( |
| 3615 | 3616 | try sema.addDeclaredHereNote(msg, union_ty); |
| 3616 | 3617 | break :msg msg; |
| 3617 | 3618 | }; |
| 3618 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 3619 | return sema.failWithOwnedErrorMsg(msg); |
| 3619 | 3620 | } |
| 3620 | 3621 | |
| 3621 | 3622 | if ((is_comptime or block.is_comptime) and |
| ... | ... | @@ -3747,7 +3748,7 @@ fn validateStructInit( |
| 3747 | 3748 | try sema.errNote(block, other_field_src, msg, "other field here", .{}); |
| 3748 | 3749 | break :msg msg; |
| 3749 | 3750 | }; |
| 3750 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 3751 | return sema.failWithOwnedErrorMsg(msg); |
| 3751 | 3752 | } |
| 3752 | 3753 | found_fields[field_index] = field_ptr; |
| 3753 | 3754 | } |
| ... | ... | @@ -3808,7 +3809,7 @@ fn validateStructInit( |
| 3808 | 3809 | .{fqn}, |
| 3809 | 3810 | ); |
| 3810 | 3811 | } |
| 3811 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 3812 | return sema.failWithOwnedErrorMsg(msg); |
| 3812 | 3813 | } |
| 3813 | 3814 | |
| 3814 | 3815 | return; |
| ... | ... | @@ -3938,7 +3939,7 @@ fn validateStructInit( |
| 3938 | 3939 | .{fqn}, |
| 3939 | 3940 | ); |
| 3940 | 3941 | } |
| 3941 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 3942 | return sema.failWithOwnedErrorMsg(msg); |
| 3942 | 3943 | } |
| 3943 | 3944 | |
| 3944 | 3945 | if (struct_is_comptime) { |
| ... | ... | @@ -4000,7 +4001,7 @@ fn zirValidateArrayInit( |
| 4000 | 4001 | } |
| 4001 | 4002 | |
| 4002 | 4003 | if (root_msg) |msg| { |
| 4003 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 4004 | return sema.failWithOwnedErrorMsg(msg); |
| 4004 | 4005 | } |
| 4005 | 4006 | } |
| 4006 | 4007 | |
| ... | ... | @@ -4180,7 +4181,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 4180 | 4181 | try sema.explainWhyTypeIsComptime(block, src, msg, src.toSrcLoc(src_decl), elem_ty); |
| 4181 | 4182 | break :msg msg; |
| 4182 | 4183 | }; |
| 4183 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 4184 | return sema.failWithOwnedErrorMsg(msg); |
| 4184 | 4185 | } |
| 4185 | 4186 | } |
| 4186 | 4187 | |
| ... | ... | @@ -4206,7 +4207,7 @@ fn failWithBadMemberAccess( |
| 4206 | 4207 | try sema.addDeclaredHereNote(msg, agg_ty); |
| 4207 | 4208 | break :msg msg; |
| 4208 | 4209 | }; |
| 4209 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 4210 | return sema.failWithOwnedErrorMsg(msg); |
| 4210 | 4211 | } |
| 4211 | 4212 | |
| 4212 | 4213 | fn failWithBadStructFieldAccess( |
| ... | ... | @@ -4232,7 +4233,7 @@ fn failWithBadStructFieldAccess( |
| 4232 | 4233 | try sema.mod.errNoteNonLazy(struct_obj.srcLoc(sema.mod), msg, "struct declared here", .{}); |
| 4233 | 4234 | break :msg msg; |
| 4234 | 4235 | }; |
| 4235 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 4236 | return sema.failWithOwnedErrorMsg(msg); |
| 4236 | 4237 | } |
| 4237 | 4238 | |
| 4238 | 4239 | fn failWithBadUnionFieldAccess( |
| ... | ... | @@ -4258,7 +4259,7 @@ fn failWithBadUnionFieldAccess( |
| 4258 | 4259 | try sema.mod.errNoteNonLazy(union_obj.srcLoc(sema.mod), msg, "union declared here", .{}); |
| 4259 | 4260 | break :msg msg; |
| 4260 | 4261 | }; |
| 4261 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 4262 | return sema.failWithOwnedErrorMsg(msg); |
| 4262 | 4263 | } |
| 4263 | 4264 | |
| 4264 | 4265 | fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void { |
| ... | ... | @@ -4747,7 +4748,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 4747 | 4748 | @import("clang.zig").Stage2ErrorMsg.delete(c_import_res.errors.ptr, c_import_res.errors.len); |
| 4748 | 4749 | break :msg msg; |
| 4749 | 4750 | }; |
| 4750 | | return sema.failWithOwnedErrorMsg(parent_block, msg); |
| 4751 | return sema.failWithOwnedErrorMsg(msg); |
| 4751 | 4752 | } |
| 4752 | 4753 | const c_import_pkg = Package.create( |
| 4753 | 4754 | sema.gpa, |
| ... | ... | @@ -4921,7 +4922,7 @@ fn analyzeBlockBody( |
| 4921 | 4922 | |
| 4922 | 4923 | break :msg msg; |
| 4923 | 4924 | }; |
| 4924 | | return sema.failWithOwnedErrorMsg(child_block, msg); |
| 4925 | return sema.failWithOwnedErrorMsg(msg); |
| 4925 | 4926 | } |
| 4926 | 4927 | const ty_inst = try sema.addType(resolved_ty); |
| 4927 | 4928 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + |
| ... | ... | @@ -5060,7 +5061,7 @@ pub fn analyzeExport( |
| 5060 | 5061 | try sema.addDeclaredHereNote(msg, exported_decl.ty); |
| 5061 | 5062 | break :msg msg; |
| 5062 | 5063 | }; |
| 5063 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 5064 | return sema.failWithOwnedErrorMsg(msg); |
| 5064 | 5065 | } |
| 5065 | 5066 | |
| 5066 | 5067 | const gpa = mod.gpa; |
| ... | ... | @@ -5150,7 +5151,7 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst |
| 5150 | 5151 | try sema.errNote(block, gop.value_ptr.src, msg, "other instance here", .{}); |
| 5151 | 5152 | break :msg msg; |
| 5152 | 5153 | }; |
| 5153 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 5154 | return sema.failWithOwnedErrorMsg(msg); |
| 5154 | 5155 | } |
| 5155 | 5156 | gop.value_ptr.* = .{ .alignment = alignment, .src = src }; |
| 5156 | 5157 | } |
| ... | ... | @@ -5311,7 +5312,14 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 5311 | 5312 | const src = inst_data.src(); |
| 5312 | 5313 | const decl_name = inst_data.get(sema.code); |
| 5313 | 5314 | const decl_index = try sema.lookupIdentifier(block, src, decl_name); |
| 5314 | | return sema.analyzeDeclRef(decl_index); |
| 5315 | return sema.analyzeDeclRef(decl_index) catch |err| switch (err) { |
| 5316 | error.AnalysisFail => { |
| 5317 | const msg = sema.err orelse return err; |
| 5318 | try sema.errNote(block, src, msg, "referenced here", .{}); |
| 5319 | return err; |
| 5320 | }, |
| 5321 | else => return err, |
| 5322 | }; |
| 5315 | 5323 | } |
| 5316 | 5324 | |
| 5317 | 5325 | fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -5413,7 +5421,7 @@ fn lookupInNamespace( |
| 5413 | 5421 | } |
| 5414 | 5422 | break :msg msg; |
| 5415 | 5423 | }; |
| 5416 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 5424 | return sema.failWithOwnedErrorMsg(msg); |
| 5417 | 5425 | }, |
| 5418 | 5426 | } |
| 5419 | 5427 | } else if (namespace.decls.getKeyAdapted(ident_name, Module.DeclAdapter{ .mod = mod })) |decl_index| { |
| ... | ... | @@ -5872,9 +5880,8 @@ fn analyzeCall( |
| 5872 | 5880 | sema.analyzeBody(&child_block, fn_info.body) catch |err| switch (err) { |
| 5873 | 5881 | error.ComptimeReturn => break :result inlining.comptime_result, |
| 5874 | 5882 | error.AnalysisFail => { |
| 5875 | | const err_msg = inlining.err orelse return err; |
| 5883 | const err_msg = sema.err orelse return err; |
| 5876 | 5884 | try sema.errNote(block, call_src, err_msg, "called from here", .{}); |
| 5877 | | if (block.inlining) |some| some.err = err_msg; |
| 5878 | 5885 | return err; |
| 5879 | 5886 | }, |
| 5880 | 5887 | else => |e| return e, |
| ... | ... | @@ -6802,7 +6809,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 6802 | 6809 | try sema.errNote(block, src, msg, "'||' merges error sets; 'or' performs boolean OR", .{}); |
| 6803 | 6810 | break :msg msg; |
| 6804 | 6811 | }; |
| 6805 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 6812 | return sema.failWithOwnedErrorMsg(msg); |
| 6806 | 6813 | } |
| 6807 | 6814 | const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs); |
| 6808 | 6815 | const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs); |
| ... | ... | @@ -6927,7 +6934,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 6927 | 6934 | try sema.addDeclaredHereNote(msg, dest_ty); |
| 6928 | 6935 | break :msg msg; |
| 6929 | 6936 | }; |
| 6930 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 6937 | return sema.failWithOwnedErrorMsg(msg); |
| 6931 | 6938 | } |
| 6932 | 6939 | return sema.addConstant(dest_ty, int_val); |
| 6933 | 6940 | } |
| ... | ... | @@ -7632,7 +7639,7 @@ fn funcCommon( |
| 7632 | 7639 | try sema.addDeclaredHereNote(msg, bare_return_type); |
| 7633 | 7640 | break :msg msg; |
| 7634 | 7641 | }; |
| 7635 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 7642 | return sema.failWithOwnedErrorMsg(msg); |
| 7636 | 7643 | } |
| 7637 | 7644 | if (!Type.fnCallingConventionAllowsZigTypes(cc_workaround) and !sema.validateExternType(return_type, .ret_ty)) { |
| 7638 | 7645 | const msg = msg: { |
| ... | ... | @@ -7647,7 +7654,7 @@ fn funcCommon( |
| 7647 | 7654 | try sema.addDeclaredHereNote(msg, return_type); |
| 7648 | 7655 | break :msg msg; |
| 7649 | 7656 | }; |
| 7650 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 7657 | return sema.failWithOwnedErrorMsg(msg); |
| 7651 | 7658 | } |
| 7652 | 7659 | |
| 7653 | 7660 | const arch = sema.mod.getTarget().cpu.arch; |
| ... | ... | @@ -7812,7 +7819,7 @@ fn analyzeParameter( |
| 7812 | 7819 | try sema.errNote(block, param_src, msg, "function is generic because of this parameter", .{}); |
| 7813 | 7820 | break :msg msg; |
| 7814 | 7821 | }; |
| 7815 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 7822 | return sema.failWithOwnedErrorMsg(msg); |
| 7816 | 7823 | } |
| 7817 | 7824 | if (this_generic and !Type.fnCallingConventionAllowsZigTypes(cc)) { |
| 7818 | 7825 | return sema.fail(block, param_src, "generic parameters not allowed in function with calling convention '{s}'", .{@tagName(cc)}); |
| ... | ... | @@ -7828,7 +7835,7 @@ fn analyzeParameter( |
| 7828 | 7835 | try sema.addDeclaredHereNote(msg, param.ty); |
| 7829 | 7836 | break :msg msg; |
| 7830 | 7837 | }; |
| 7831 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 7838 | return sema.failWithOwnedErrorMsg(msg); |
| 7832 | 7839 | } |
| 7833 | 7840 | if (!Type.fnCallingConventionAllowsZigTypes(cc) and !sema.validateExternType(param.ty, .param_ty)) { |
| 7834 | 7841 | const msg = msg: { |
| ... | ... | @@ -7843,7 +7850,7 @@ fn analyzeParameter( |
| 7843 | 7850 | try sema.addDeclaredHereNote(msg, param.ty); |
| 7844 | 7851 | break :msg msg; |
| 7845 | 7852 | }; |
| 7846 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 7853 | return sema.failWithOwnedErrorMsg(msg); |
| 7847 | 7854 | } |
| 7848 | 7855 | if (requires_comptime and !param.is_comptime) { |
| 7849 | 7856 | const msg = msg: { |
| ... | ... | @@ -7855,7 +7862,7 @@ fn analyzeParameter( |
| 7855 | 7862 | try sema.addDeclaredHereNote(msg, param.ty); |
| 7856 | 7863 | break :msg msg; |
| 7857 | 7864 | }; |
| 7858 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 7865 | return sema.failWithOwnedErrorMsg(msg); |
| 7859 | 7866 | } |
| 7860 | 7867 | } |
| 7861 | 7868 | |
| ... | ... | @@ -8318,7 +8325,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 8318 | 8325 | |
| 8319 | 8326 | break :msg msg; |
| 8320 | 8327 | }; |
| 8321 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 8328 | return sema.failWithOwnedErrorMsg(msg); |
| 8322 | 8329 | }, |
| 8323 | 8330 | |
| 8324 | 8331 | .Pointer => { |
| ... | ... | @@ -8333,7 +8340,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 8333 | 8340 | |
| 8334 | 8341 | break :msg msg; |
| 8335 | 8342 | }; |
| 8336 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 8343 | return sema.failWithOwnedErrorMsg(msg); |
| 8337 | 8344 | }, |
| 8338 | 8345 | .Struct, .Union => if (dest_ty.containerLayout() == .Auto) { |
| 8339 | 8346 | const container = switch (dest_ty.zigTypeTag()) { |
| ... | ... | @@ -8383,7 +8390,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 8383 | 8390 | |
| 8384 | 8391 | break :msg msg; |
| 8385 | 8392 | }; |
| 8386 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 8393 | return sema.failWithOwnedErrorMsg(msg); |
| 8387 | 8394 | }, |
| 8388 | 8395 | .Pointer => { |
| 8389 | 8396 | const msg = msg: { |
| ... | ... | @@ -8397,7 +8404,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 8397 | 8404 | |
| 8398 | 8405 | break :msg msg; |
| 8399 | 8406 | }; |
| 8400 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 8407 | return sema.failWithOwnedErrorMsg(msg); |
| 8401 | 8408 | }, |
| 8402 | 8409 | .Struct, .Union => if (operand_ty.containerLayout() == .Auto) { |
| 8403 | 8410 | const container = switch (operand_ty.zigTypeTag()) { |
| ... | ... | @@ -8663,7 +8670,7 @@ fn zirSwitchCapture( |
| 8663 | 8670 | try sema.errNote(block, item_src, msg, "type '{}' here", .{field.ty.fmt(sema.mod)}); |
| 8664 | 8671 | break :msg msg; |
| 8665 | 8672 | }; |
| 8666 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 8673 | return sema.failWithOwnedErrorMsg(msg); |
| 8667 | 8674 | } |
| 8668 | 8675 | } |
| 8669 | 8676 | |
| ... | ... | @@ -8786,7 +8793,7 @@ fn zirSwitchCond( |
| 8786 | 8793 | } |
| 8787 | 8794 | break :msg msg; |
| 8788 | 8795 | }; |
| 8789 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 8796 | return sema.failWithOwnedErrorMsg(msg); |
| 8790 | 8797 | }; |
| 8791 | 8798 | return sema.unionToTag(block, enum_ty, operand, src); |
| 8792 | 8799 | }, |
| ... | ... | @@ -8875,7 +8882,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8875 | 8882 | ); |
| 8876 | 8883 | break :msg msg; |
| 8877 | 8884 | }; |
| 8878 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 8885 | return sema.failWithOwnedErrorMsg(msg); |
| 8879 | 8886 | } |
| 8880 | 8887 | |
| 8881 | 8888 | const target = sema.mod.getTarget(); |
| ... | ... | @@ -8979,7 +8986,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8979 | 8986 | ); |
| 8980 | 8987 | break :msg msg; |
| 8981 | 8988 | }; |
| 8982 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 8989 | return sema.failWithOwnedErrorMsg(msg); |
| 8983 | 8990 | } else if (special_prong == .none and operand_ty.isNonexhaustiveEnum() and !union_originally) { |
| 8984 | 8991 | return sema.fail( |
| 8985 | 8992 | block, |
| ... | ... | @@ -9079,7 +9086,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 9079 | 9086 | if (maybe_msg) |msg| { |
| 9080 | 9087 | maybe_msg = null; |
| 9081 | 9088 | try sema.addDeclaredHereNote(msg, operand_ty); |
| 9082 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 9089 | return sema.failWithOwnedErrorMsg(msg); |
| 9083 | 9090 | } |
| 9084 | 9091 | |
| 9085 | 9092 | if (special_prong == .@"else" and seen_errors.count() == operand_ty.errorSetNames().len) { |
| ... | ... | @@ -9888,7 +9895,7 @@ fn validateSwitchDupe( |
| 9888 | 9895 | ); |
| 9889 | 9896 | break :msg msg; |
| 9890 | 9897 | }; |
| 9891 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 9898 | return sema.failWithOwnedErrorMsg(msg); |
| 9892 | 9899 | } |
| 9893 | 9900 | |
| 9894 | 9901 | fn validateSwitchItemBool( |
| ... | ... | @@ -9958,7 +9965,7 @@ fn validateSwitchNoRange( |
| 9958 | 9965 | ); |
| 9959 | 9966 | break :msg msg; |
| 9960 | 9967 | }; |
| 9961 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 9968 | return sema.failWithOwnedErrorMsg(msg); |
| 9962 | 9969 | } |
| 9963 | 9970 | |
| 9964 | 9971 | fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -12882,7 +12889,7 @@ fn analyzeCmpUnionTag( |
| 12882 | 12889 | try sema.mod.errNoteNonLazy(union_ty.declSrcLoc(sema.mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(sema.mod)}); |
| 12883 | 12890 | break :msg msg; |
| 12884 | 12891 | }; |
| 12885 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 12892 | return sema.failWithOwnedErrorMsg(msg); |
| 12886 | 12893 | }; |
| 12887 | 12894 | // Coerce both the union and the tag to the union's tag type, and then execute the |
| 12888 | 12895 | // enum comparison codepath. |
| ... | ... | @@ -13143,6 +13150,36 @@ fn zirClosureGet( |
| 13143 | 13150 | scope = scope.parent.?; |
| 13144 | 13151 | } else unreachable; |
| 13145 | 13152 | |
| 13153 | if (tv.val.tag() == .generic_poison and !block.is_typeof and !block.is_comptime and sema.func != null) { |
| 13154 | const msg = msg: { |
| 13155 | const name = name: { |
| 13156 | const file = sema.owner_decl.getFileScope(); |
| 13157 | const tree = file.getTree(sema.mod.gpa) catch |err| { |
| 13158 | // In this case we emit a warning + a less precise source location. |
| 13159 | log.warn("unable to load {s}: {s}", .{ |
| 13160 | file.sub_file_path, @errorName(err), |
| 13161 | }); |
| 13162 | break :name null; |
| 13163 | }; |
| 13164 | const node = sema.owner_decl.relativeToNodeIndex(inst_data.src_node); |
| 13165 | const token = tree.nodes.items(.main_token)[node]; |
| 13166 | break :name tree.tokenSlice(token); |
| 13167 | }; |
| 13168 | |
| 13169 | const msg = if (name) |some| |
| 13170 | try sema.errMsg(block, inst_data.src(), "'{s}' not accessible from inner function", .{some}) |
| 13171 | else |
| 13172 | try sema.errMsg(block, inst_data.src(), "variable not accessible from inner function", .{}); |
| 13173 | errdefer msg.destroy(sema.gpa); |
| 13174 | |
| 13175 | try sema.errNote(block, LazySrcLoc.nodeOffset(0), msg, "crossed function definition here", .{}); |
| 13176 | |
| 13177 | // TODO add "declared here" note |
| 13178 | break :msg msg; |
| 13179 | }; |
| 13180 | return sema.failWithOwnedErrorMsg(msg); |
| 13181 | } |
| 13182 | |
| 13146 | 13183 | return sema.addConstant(tv.ty, tv.val); |
| 13147 | 13184 | } |
| 13148 | 13185 | |
| ... | ... | @@ -14877,7 +14914,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 14877 | 14914 | try sema.addDeclaredHereNote(msg, elem_ty); |
| 14878 | 14915 | break :msg msg; |
| 14879 | 14916 | }; |
| 14880 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 14917 | return sema.failWithOwnedErrorMsg(msg); |
| 14881 | 14918 | } |
| 14882 | 14919 | if (elem_ty.zigTypeTag() == .Opaque) { |
| 14883 | 14920 | return sema.fail(block, elem_ty_src, "C pointers cannot point to opaque types", .{}); |
| ... | ... | @@ -15048,7 +15085,7 @@ fn zirStructInit( |
| 15048 | 15085 | try sema.errNote(block, other_field_src, msg, "other field here", .{}); |
| 15049 | 15086 | break :msg msg; |
| 15050 | 15087 | }; |
| 15051 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 15088 | return sema.failWithOwnedErrorMsg(msg); |
| 15052 | 15089 | } |
| 15053 | 15090 | found_fields[field_index] = item.data.field_type; |
| 15054 | 15091 | field_inits[field_index] = try sema.resolveInst(item.data.init); |
| ... | ... | @@ -15189,7 +15226,7 @@ fn finishStructInit( |
| 15189 | 15226 | .{fqn}, |
| 15190 | 15227 | ); |
| 15191 | 15228 | } |
| 15192 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 15229 | return sema.failWithOwnedErrorMsg(msg); |
| 15193 | 15230 | } |
| 15194 | 15231 | |
| 15195 | 15232 | const is_comptime = for (field_inits) |field_init| { |
| ... | ... | @@ -15264,7 +15301,7 @@ fn zirStructInitAnon( |
| 15264 | 15301 | try sema.errNote(block, prev_source, msg, "other field here", .{}); |
| 15265 | 15302 | break :msg msg; |
| 15266 | 15303 | }; |
| 15267 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 15304 | return sema.failWithOwnedErrorMsg(msg); |
| 15268 | 15305 | } |
| 15269 | 15306 | gop.value_ptr.* = @intCast(u32, i); |
| 15270 | 15307 | |
| ... | ... | @@ -15280,7 +15317,7 @@ fn zirStructInitAnon( |
| 15280 | 15317 | try sema.addDeclaredHereNote(msg, types[i]); |
| 15281 | 15318 | break :msg msg; |
| 15282 | 15319 | }; |
| 15283 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 15320 | return sema.failWithOwnedErrorMsg(msg); |
| 15284 | 15321 | } |
| 15285 | 15322 | const init_src = src; // TODO better source location |
| 15286 | 15323 | if (try sema.resolveMaybeUndefVal(block, init_src, init)) |init_val| { |
| ... | ... | @@ -15478,7 +15515,7 @@ fn zirArrayInitAnon( |
| 15478 | 15515 | try sema.addDeclaredHereNote(msg, types[i]); |
| 15479 | 15516 | break :msg msg; |
| 15480 | 15517 | }; |
| 15481 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 15518 | return sema.failWithOwnedErrorMsg(msg); |
| 15482 | 15519 | } |
| 15483 | 15520 | if (try sema.resolveMaybeUndefVal(block, operand_src, elem)) |val| { |
| 15484 | 15521 | values[i] = val; |
| ... | ... | @@ -15792,7 +15829,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 15792 | 15829 | try sema.addDeclaredHereNote(msg, operand_ty); |
| 15793 | 15830 | break :msg msg; |
| 15794 | 15831 | }; |
| 15795 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 15832 | return sema.failWithOwnedErrorMsg(msg); |
| 15796 | 15833 | }, |
| 15797 | 15834 | else => return sema.fail(block, operand_src, "expected enum or union; found '{}'", .{ |
| 15798 | 15835 | operand_ty.fmt(mod), |
| ... | ... | @@ -15811,7 +15848,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 15811 | 15848 | try mod.errNoteNonLazy(enum_decl.srcLoc(), msg, "declared here", .{}); |
| 15812 | 15849 | break :msg msg; |
| 15813 | 15850 | }; |
| 15814 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 15851 | return sema.failWithOwnedErrorMsg(msg); |
| 15815 | 15852 | }; |
| 15816 | 15853 | const field_name = enum_ty.enumFieldName(field_index); |
| 15817 | 15854 | return sema.addStrLit(block, field_name); |
| ... | ... | @@ -15961,7 +15998,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 15961 | 15998 | try sema.addDeclaredHereNote(msg, elem_ty); |
| 15962 | 15999 | break :msg msg; |
| 15963 | 16000 | }; |
| 15964 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 16001 | return sema.failWithOwnedErrorMsg(msg); |
| 15965 | 16002 | } |
| 15966 | 16003 | if (elem_ty.zigTypeTag() == .Opaque) { |
| 15967 | 16004 | return sema.fail(block, src, "C pointers cannot point to opaque types", .{}); |
| ... | ... | @@ -16364,7 +16401,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 16364 | 16401 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| 16365 | 16402 | break :msg msg; |
| 16366 | 16403 | }; |
| 16367 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 16404 | return sema.failWithOwnedErrorMsg(msg); |
| 16368 | 16405 | } |
| 16369 | 16406 | } |
| 16370 | 16407 | |
| ... | ... | @@ -16398,7 +16435,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 16398 | 16435 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| 16399 | 16436 | break :msg msg; |
| 16400 | 16437 | }; |
| 16401 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 16438 | return sema.failWithOwnedErrorMsg(msg); |
| 16402 | 16439 | } |
| 16403 | 16440 | } |
| 16404 | 16441 | |
| ... | ... | @@ -16868,7 +16905,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 16868 | 16905 | try sema.addDeclaredHereNote(msg, dest_ty); |
| 16869 | 16906 | break :msg msg; |
| 16870 | 16907 | }; |
| 16871 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 16908 | return sema.failWithOwnedErrorMsg(msg); |
| 16872 | 16909 | } |
| 16873 | 16910 | |
| 16874 | 16911 | if (maybe_operand_val) |val| { |
| ... | ... | @@ -16886,7 +16923,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 16886 | 16923 | try sema.addDeclaredHereNote(msg, dest_ty); |
| 16887 | 16924 | break :msg msg; |
| 16888 | 16925 | }; |
| 16889 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 16926 | return sema.failWithOwnedErrorMsg(msg); |
| 16890 | 16927 | } |
| 16891 | 16928 | } |
| 16892 | 16929 | |
| ... | ... | @@ -17024,7 +17061,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17024 | 17061 | }); |
| 17025 | 17062 | break :msg msg; |
| 17026 | 17063 | }; |
| 17027 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 17064 | return sema.failWithOwnedErrorMsg(msg); |
| 17028 | 17065 | } |
| 17029 | 17066 | } |
| 17030 | 17067 | |
| ... | ... | @@ -17315,7 +17352,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 |
| 17315 | 17352 | try sema.addDeclaredHereNote(msg, ty); |
| 17316 | 17353 | break :msg msg; |
| 17317 | 17354 | }; |
| 17318 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 17355 | return sema.failWithOwnedErrorMsg(msg); |
| 17319 | 17356 | }, |
| 17320 | 17357 | } |
| 17321 | 17358 | |
| ... | ... | @@ -17419,7 +17456,7 @@ fn checkPtrOperand( |
| 17419 | 17456 | |
| 17420 | 17457 | break :msg msg; |
| 17421 | 17458 | }; |
| 17422 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 17459 | return sema.failWithOwnedErrorMsg(msg); |
| 17423 | 17460 | }, |
| 17424 | 17461 | .Optional => if (ty.isPtrLikeOptional()) return, |
| 17425 | 17462 | else => {}, |
| ... | ... | @@ -17449,7 +17486,7 @@ fn checkPtrType( |
| 17449 | 17486 | |
| 17450 | 17487 | break :msg msg; |
| 17451 | 17488 | }; |
| 17452 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 17489 | return sema.failWithOwnedErrorMsg(msg); |
| 17453 | 17490 | }, |
| 17454 | 17491 | .Optional => if (ty.isPtrLikeOptional()) return, |
| 17455 | 17492 | else => {}, |
| ... | ... | @@ -17585,7 +17622,7 @@ fn checkComptimeVarStore( |
| 17585 | 17622 | try sema.errNote(block, cond_src, msg, "runtime condition here", .{}); |
| 17586 | 17623 | break :msg msg; |
| 17587 | 17624 | }; |
| 17588 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 17625 | return sema.failWithOwnedErrorMsg(msg); |
| 17589 | 17626 | } |
| 17590 | 17627 | if (block.runtime_loop) |loop_src| { |
| 17591 | 17628 | const msg = msg: { |
| ... | ... | @@ -17594,7 +17631,7 @@ fn checkComptimeVarStore( |
| 17594 | 17631 | try sema.errNote(block, loop_src, msg, "non-inline loop here", .{}); |
| 17595 | 17632 | break :msg msg; |
| 17596 | 17633 | }; |
| 17597 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 17634 | return sema.failWithOwnedErrorMsg(msg); |
| 17598 | 17635 | } |
| 17599 | 17636 | unreachable; |
| 17600 | 17637 | } |
| ... | ... | @@ -17731,7 +17768,7 @@ fn checkVectorizableBinaryOperands( |
| 17731 | 17768 | try sema.errNote(block, rhs_src, msg, "length {d} here", .{rhs_len}); |
| 17732 | 17769 | break :msg msg; |
| 17733 | 17770 | }; |
| 17734 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 17771 | return sema.failWithOwnedErrorMsg(msg); |
| 17735 | 17772 | } |
| 17736 | 17773 | } else { |
| 17737 | 17774 | const msg = msg: { |
| ... | ... | @@ -17748,7 +17785,7 @@ fn checkVectorizableBinaryOperands( |
| 17748 | 17785 | } |
| 17749 | 17786 | break :msg msg; |
| 17750 | 17787 | }; |
| 17751 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 17788 | return sema.failWithOwnedErrorMsg(msg); |
| 17752 | 17789 | } |
| 17753 | 17790 | } |
| 17754 | 17791 | |
| ... | ... | @@ -18148,7 +18185,7 @@ fn analyzeShuffle( |
| 18148 | 18185 | |
| 18149 | 18186 | break :msg msg; |
| 18150 | 18187 | }; |
| 18151 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 18188 | return sema.failWithOwnedErrorMsg(msg); |
| 18152 | 18189 | } |
| 18153 | 18190 | } |
| 18154 | 18191 | |
| ... | ... | @@ -18744,7 +18781,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 18744 | 18781 | try sema.addDeclaredHereNote(msg, struct_ty); |
| 18745 | 18782 | break :msg msg; |
| 18746 | 18783 | }; |
| 18747 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 18784 | return sema.failWithOwnedErrorMsg(msg); |
| 18748 | 18785 | } |
| 18749 | 18786 | return sema.addConstant(result_ptr, payload.data.container_ptr); |
| 18750 | 18787 | } |
| ... | ... | @@ -19544,7 +19581,7 @@ fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: |
| 19544 | 19581 | } |
| 19545 | 19582 | break :msg msg; |
| 19546 | 19583 | }; |
| 19547 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 19584 | return sema.failWithOwnedErrorMsg(msg); |
| 19548 | 19585 | } |
| 19549 | 19586 | try sema.requireFunctionBlock(block, src); |
| 19550 | 19587 | } |
| ... | ... | @@ -19573,7 +19610,7 @@ fn validateVarType( |
| 19573 | 19610 | |
| 19574 | 19611 | break :msg msg; |
| 19575 | 19612 | }; |
| 19576 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 19613 | return sema.failWithOwnedErrorMsg(msg); |
| 19577 | 19614 | } |
| 19578 | 19615 | |
| 19579 | 19616 | fn validateRunTimeType( |
| ... | ... | @@ -20275,7 +20312,7 @@ fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void { |
| 20275 | 20312 | "use @setEvalBranchQuota() to raise the branch limit from {d}", |
| 20276 | 20313 | .{sema.branch_quota}, |
| 20277 | 20314 | ); |
| 20278 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 20315 | return sema.failWithOwnedErrorMsg(msg); |
| 20279 | 20316 | } |
| 20280 | 20317 | } |
| 20281 | 20318 | |
| ... | ... | @@ -20383,7 +20420,7 @@ fn fieldVal( |
| 20383 | 20420 | try sema.addDeclaredHereNote(msg, child_type); |
| 20384 | 20421 | break :msg msg; |
| 20385 | 20422 | }; |
| 20386 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 20423 | return sema.failWithOwnedErrorMsg(msg); |
| 20387 | 20424 | } else (try sema.mod.getErrorValue(field_name)).key; |
| 20388 | 20425 | |
| 20389 | 20426 | return sema.addConstant( |
| ... | ... | @@ -20438,7 +20475,7 @@ fn fieldVal( |
| 20438 | 20475 | if (child_type.zigTypeTag() == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{}); |
| 20439 | 20476 | break :msg msg; |
| 20440 | 20477 | }; |
| 20441 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 20478 | return sema.failWithOwnedErrorMsg(msg); |
| 20442 | 20479 | }, |
| 20443 | 20480 | } |
| 20444 | 20481 | }, |
| ... | ... | @@ -20776,7 +20813,7 @@ fn fieldCallBind( |
| 20776 | 20813 | try sema.addDeclaredHereNote(msg, concrete_ty); |
| 20777 | 20814 | break :msg msg; |
| 20778 | 20815 | }; |
| 20779 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 20816 | return sema.failWithOwnedErrorMsg(msg); |
| 20780 | 20817 | } |
| 20781 | 20818 | |
| 20782 | 20819 | fn finishFieldCallBind( |
| ... | ... | @@ -20831,7 +20868,7 @@ fn namespaceLookup( |
| 20831 | 20868 | try sema.mod.errNoteNonLazy(decl.srcLoc(), msg, "declared here", .{}); |
| 20832 | 20869 | break :msg msg; |
| 20833 | 20870 | }; |
| 20834 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 20871 | return sema.failWithOwnedErrorMsg(msg); |
| 20835 | 20872 | } |
| 20836 | 20873 | return decl_index; |
| 20837 | 20874 | } |
| ... | ... | @@ -20846,7 +20883,14 @@ fn namespaceLookupRef( |
| 20846 | 20883 | decl_name: []const u8, |
| 20847 | 20884 | ) CompileError!?Air.Inst.Ref { |
| 20848 | 20885 | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; |
| 20849 | | return try sema.analyzeDeclRef(decl); |
| 20886 | return sema.analyzeDeclRef(decl) catch |err| switch (err) { |
| 20887 | error.AnalysisFail => { |
| 20888 | const msg = sema.err orelse return err; |
| 20889 | try sema.errNote(block, src, msg, "referenced here", .{}); |
| 20890 | return err; |
| 20891 | }, |
| 20892 | else => return err, |
| 20893 | }; |
| 20850 | 20894 | } |
| 20851 | 20895 | |
| 20852 | 20896 | fn namespaceLookupVal( |
| ... | ... | @@ -21164,7 +21208,7 @@ fn unionFieldPtr( |
| 21164 | 21208 | try sema.addDeclaredHereNote(msg, union_ty); |
| 21165 | 21209 | break :msg msg; |
| 21166 | 21210 | }; |
| 21167 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 21211 | return sema.failWithOwnedErrorMsg(msg); |
| 21168 | 21212 | } |
| 21169 | 21213 | }, |
| 21170 | 21214 | .Packed, .Extern => {}, |
| ... | ... | @@ -21234,7 +21278,7 @@ fn unionFieldVal( |
| 21234 | 21278 | try sema.addDeclaredHereNote(msg, union_ty); |
| 21235 | 21279 | break :msg msg; |
| 21236 | 21280 | }; |
| 21237 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 21281 | return sema.failWithOwnedErrorMsg(msg); |
| 21238 | 21282 | } |
| 21239 | 21283 | }, |
| 21240 | 21284 | .Packed, .Extern => { |
| ... | ... | @@ -21408,7 +21452,7 @@ fn validateRuntimeElemAccess( |
| 21408 | 21452 | |
| 21409 | 21453 | break :msg msg; |
| 21410 | 21454 | }; |
| 21411 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 21455 | return sema.failWithOwnedErrorMsg(msg); |
| 21412 | 21456 | } |
| 21413 | 21457 | } |
| 21414 | 21458 | |
| ... | ... | @@ -22184,7 +22228,7 @@ fn coerceExtra( |
| 22184 | 22228 | try sema.addDeclaredHereNote(msg, dest_ty); |
| 22185 | 22229 | break :msg msg; |
| 22186 | 22230 | }; |
| 22187 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 22231 | return sema.failWithOwnedErrorMsg(msg); |
| 22188 | 22232 | }; |
| 22189 | 22233 | return sema.addConstant( |
| 22190 | 22234 | dest_ty, |
| ... | ... | @@ -22312,7 +22356,7 @@ fn coerceExtra( |
| 22312 | 22356 | try sema.mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl), msg, "'noreturn' declared here", .{}); |
| 22313 | 22357 | break :msg msg; |
| 22314 | 22358 | }; |
| 22315 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 22359 | return sema.failWithOwnedErrorMsg(msg); |
| 22316 | 22360 | } |
| 22317 | 22361 | |
| 22318 | 22362 | const msg = msg: { |
| ... | ... | @@ -22353,7 +22397,7 @@ fn coerceExtra( |
| 22353 | 22397 | |
| 22354 | 22398 | break :msg msg; |
| 22355 | 22399 | }; |
| 22356 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 22400 | return sema.failWithOwnedErrorMsg(msg); |
| 22357 | 22401 | } |
| 22358 | 22402 | |
| 22359 | 22403 | const InMemoryCoercionResult = union(enum) { |
| ... | ... | @@ -24418,7 +24462,7 @@ fn coerceEnumToUnion( |
| 24418 | 24462 | try sema.addDeclaredHereNote(msg, union_ty); |
| 24419 | 24463 | break :msg msg; |
| 24420 | 24464 | }; |
| 24421 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 24465 | return sema.failWithOwnedErrorMsg(msg); |
| 24422 | 24466 | }; |
| 24423 | 24467 | |
| 24424 | 24468 | const enum_tag = try sema.coerce(block, tag_ty, inst, inst_src); |
| ... | ... | @@ -24433,7 +24477,7 @@ fn coerceEnumToUnion( |
| 24433 | 24477 | try sema.addDeclaredHereNote(msg, union_ty); |
| 24434 | 24478 | break :msg msg; |
| 24435 | 24479 | }; |
| 24436 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 24480 | return sema.failWithOwnedErrorMsg(msg); |
| 24437 | 24481 | }; |
| 24438 | 24482 | const field = union_obj.fields.values()[field_index]; |
| 24439 | 24483 | const field_ty = try sema.resolveTypeFields(block, inst_src, field.ty); |
| ... | ... | @@ -24449,7 +24493,7 @@ fn coerceEnumToUnion( |
| 24449 | 24493 | try sema.addDeclaredHereNote(msg, union_ty); |
| 24450 | 24494 | break :msg msg; |
| 24451 | 24495 | }; |
| 24452 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 24496 | return sema.failWithOwnedErrorMsg(msg); |
| 24453 | 24497 | }; |
| 24454 | 24498 | |
| 24455 | 24499 | return sema.addConstant(union_ty, try Value.Tag.@"union".create(sema.arena, .{ |
| ... | ... | @@ -24469,7 +24513,7 @@ fn coerceEnumToUnion( |
| 24469 | 24513 | try sema.addDeclaredHereNote(msg, tag_ty); |
| 24470 | 24514 | break :msg msg; |
| 24471 | 24515 | }; |
| 24472 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 24516 | return sema.failWithOwnedErrorMsg(msg); |
| 24473 | 24517 | } |
| 24474 | 24518 | |
| 24475 | 24519 | // If the union has all fields 0 bits, the union value is just the enum value. |
| ... | ... | @@ -24498,7 +24542,7 @@ fn coerceEnumToUnion( |
| 24498 | 24542 | try sema.addDeclaredHereNote(msg, union_ty); |
| 24499 | 24543 | break :msg msg; |
| 24500 | 24544 | }; |
| 24501 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 24545 | return sema.failWithOwnedErrorMsg(msg); |
| 24502 | 24546 | } |
| 24503 | 24547 | |
| 24504 | 24548 | fn coerceAnonStructToUnion( |
| ... | ... | @@ -24527,7 +24571,7 @@ fn coerceAnonStructToUnion( |
| 24527 | 24571 | try sema.addDeclaredHereNote(msg, union_ty); |
| 24528 | 24572 | break :msg msg; |
| 24529 | 24573 | }; |
| 24530 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 24574 | return sema.failWithOwnedErrorMsg(msg); |
| 24531 | 24575 | } |
| 24532 | 24576 | |
| 24533 | 24577 | const field_name = anon_struct.names[0]; |
| ... | ... | @@ -24587,7 +24631,7 @@ fn coerceArrayLike( |
| 24587 | 24631 | try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len}); |
| 24588 | 24632 | break :msg msg; |
| 24589 | 24633 | }; |
| 24590 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 24634 | return sema.failWithOwnedErrorMsg(msg); |
| 24591 | 24635 | } |
| 24592 | 24636 | |
| 24593 | 24637 | const dest_elem_ty = dest_ty.childType(); |
| ... | ... | @@ -24659,7 +24703,7 @@ fn coerceTupleToArray( |
| 24659 | 24703 | try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len}); |
| 24660 | 24704 | break :msg msg; |
| 24661 | 24705 | }; |
| 24662 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 24706 | return sema.failWithOwnedErrorMsg(msg); |
| 24663 | 24707 | } |
| 24664 | 24708 | |
| 24665 | 24709 | const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLenIncludingSentinel()); |
| ... | ... | @@ -24822,7 +24866,7 @@ fn coerceTupleToStruct( |
| 24822 | 24866 | |
| 24823 | 24867 | if (root_msg) |msg| { |
| 24824 | 24868 | try sema.addDeclaredHereNote(msg, struct_ty); |
| 24825 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 24869 | return sema.failWithOwnedErrorMsg(msg); |
| 24826 | 24870 | } |
| 24827 | 24871 | |
| 24828 | 24872 | if (runtime_src) |rs| { |
| ... | ... | @@ -24926,7 +24970,7 @@ fn coerceTupleToTuple( |
| 24926 | 24970 | |
| 24927 | 24971 | if (root_msg) |msg| { |
| 24928 | 24972 | try sema.addDeclaredHereNote(msg, tuple_ty); |
| 24929 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 24973 | return sema.failWithOwnedErrorMsg(msg); |
| 24930 | 24974 | } |
| 24931 | 24975 | |
| 24932 | 24976 | if (runtime_src) |rs| { |
| ... | ... | @@ -24949,7 +24993,14 @@ fn analyzeDeclVal( |
| 24949 | 24993 | if (sema.decl_val_table.get(decl_index)) |result| { |
| 24950 | 24994 | return result; |
| 24951 | 24995 | } |
| 24952 | | const decl_ref = try sema.analyzeDeclRef(decl_index); |
| 24996 | const decl_ref = sema.analyzeDeclRef(decl_index) catch |err| switch (err) { |
| 24997 | error.AnalysisFail => { |
| 24998 | const msg = sema.err orelse return err; |
| 24999 | try sema.errNote(block, src, msg, "referenced here", .{}); |
| 25000 | return err; |
| 25001 | }, |
| 25002 | else => return err, |
| 25003 | }; |
| 24953 | 25004 | const result = try sema.analyzeLoad(block, src, decl_ref, src); |
| 24954 | 25005 | if (Air.refToIndex(result)) |index| { |
| 24955 | 25006 | if (sema.air_instructions.items(.tag)[index] == .constant and !block.is_typeof) { |
| ... | ... | @@ -24960,6 +25011,12 @@ fn analyzeDeclVal( |
| 24960 | 25011 | } |
| 24961 | 25012 | |
| 24962 | 25013 | fn ensureDeclAnalyzed(sema: *Sema, decl_index: Decl.Index) CompileError!void { |
| 25014 | const decl = sema.mod.declPtr(decl_index); |
| 25015 | if (decl.analysis == .in_progress) { |
| 25016 | const msg = try Module.ErrorMsg.create(sema.gpa, decl.srcLoc(), "dependency loop detected", .{}); |
| 25017 | return sema.failWithOwnedErrorMsg(msg); |
| 25018 | } |
| 25019 | |
| 24963 | 25020 | sema.mod.ensureDeclAnalyzed(decl_index) catch |err| { |
| 24964 | 25021 | if (sema.owner_func) |owner_func| { |
| 24965 | 25022 | owner_func.state = .dependency_failure; |
| ... | ... | @@ -25491,7 +25548,7 @@ fn analyzeSlice( |
| 25491 | 25548 | |
| 25492 | 25549 | break :msg msg; |
| 25493 | 25550 | }; |
| 25494 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 25551 | return sema.failWithOwnedErrorMsg(msg); |
| 25495 | 25552 | } |
| 25496 | 25553 | } |
| 25497 | 25554 | } |
| ... | ... | @@ -26440,7 +26497,7 @@ fn resolvePeerTypes( |
| 26440 | 26497 | |
| 26441 | 26498 | break :msg msg; |
| 26442 | 26499 | }; |
| 26443 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 26500 | return sema.failWithOwnedErrorMsg(msg); |
| 26444 | 26501 | } |
| 26445 | 26502 | |
| 26446 | 26503 | const chosen_ty = sema.typeOf(chosen); |
| ... | ... | @@ -26599,21 +26656,41 @@ fn resolveStructLayout( |
| 26599 | 26656 | switch (struct_obj.status) { |
| 26600 | 26657 | .none, .have_field_types => {}, |
| 26601 | 26658 | .field_types_wip, .layout_wip => { |
| 26602 | | return sema.fail(block, src, "struct '{}' depends on itself", .{ty.fmt(sema.mod)}); |
| 26659 | const msg = try Module.ErrorMsg.create( |
| 26660 | sema.gpa, |
| 26661 | struct_obj.srcLoc(sema.mod), |
| 26662 | "struct '{}' depends on itself", |
| 26663 | .{ty.fmt(sema.mod)}, |
| 26664 | ); |
| 26665 | return sema.failWithOwnedErrorMsg(msg); |
| 26603 | 26666 | }, |
| 26604 | 26667 | .have_layout, .fully_resolved_wip, .fully_resolved => return, |
| 26605 | 26668 | } |
| 26606 | 26669 | struct_obj.status = .layout_wip; |
| 26607 | | for (struct_obj.fields.values()) |field| { |
| 26608 | | try sema.resolveTypeLayout(block, src, field.ty); |
| 26670 | for (struct_obj.fields.values()) |field, i| { |
| 26671 | sema.resolveTypeLayout(block, src, field.ty) catch |err| switch (err) { |
| 26672 | error.AnalysisFail => { |
| 26673 | const msg = sema.err orelse return err; |
| 26674 | try sema.addFieldErrNote(block, ty, i, msg, "while checking this field", .{}); |
| 26675 | return err; |
| 26676 | }, |
| 26677 | else => return err, |
| 26678 | }; |
| 26609 | 26679 | } |
| 26610 | 26680 | struct_obj.status = .have_layout; |
| 26611 | 26681 | |
| 26612 | 26682 | // In case of querying the ABI alignment of this struct, we will ask |
| 26613 | 26683 | // for hasRuntimeBits() of each field, so we need "requires comptime" |
| 26614 | 26684 | // to be known already before this function returns. |
| 26615 | | for (struct_obj.fields.values()) |field| { |
| 26616 | | _ = try sema.typeRequiresComptime(block, src, field.ty); |
| 26685 | for (struct_obj.fields.values()) |field, i| { |
| 26686 | _ = sema.typeRequiresComptime(block, src, field.ty) catch |err| switch (err) { |
| 26687 | error.AnalysisFail => { |
| 26688 | const msg = sema.err orelse return err; |
| 26689 | try sema.addFieldErrNote(block, ty, i, msg, "while checking this field", .{}); |
| 26690 | return err; |
| 26691 | }, |
| 26692 | else => return err, |
| 26693 | }; |
| 26617 | 26694 | } |
| 26618 | 26695 | } |
| 26619 | 26696 | // otherwise it's a tuple; no need to resolve anything |
| ... | ... | @@ -26630,13 +26707,26 @@ fn resolveUnionLayout( |
| 26630 | 26707 | switch (union_obj.status) { |
| 26631 | 26708 | .none, .have_field_types => {}, |
| 26632 | 26709 | .field_types_wip, .layout_wip => { |
| 26633 | | return sema.fail(block, src, "union '{}' depends on itself", .{ty.fmt(sema.mod)}); |
| 26710 | const msg = try Module.ErrorMsg.create( |
| 26711 | sema.gpa, |
| 26712 | union_obj.srcLoc(sema.mod), |
| 26713 | "union '{}' depends on itself", |
| 26714 | .{ty.fmt(sema.mod)}, |
| 26715 | ); |
| 26716 | return sema.failWithOwnedErrorMsg(msg); |
| 26634 | 26717 | }, |
| 26635 | 26718 | .have_layout, .fully_resolved_wip, .fully_resolved => return, |
| 26636 | 26719 | } |
| 26637 | 26720 | union_obj.status = .layout_wip; |
| 26638 | | for (union_obj.fields.values()) |field| { |
| 26639 | | try sema.resolveTypeLayout(block, src, field.ty); |
| 26721 | for (union_obj.fields.values()) |field, i| { |
| 26722 | sema.resolveTypeLayout(block, src, field.ty) catch |err| switch (err) { |
| 26723 | error.AnalysisFail => { |
| 26724 | const msg = sema.err orelse return err; |
| 26725 | try sema.addFieldErrNote(block, ty, i, msg, "while checking this field", .{}); |
| 26726 | return err; |
| 26727 | }, |
| 26728 | else => return err, |
| 26729 | }; |
| 26640 | 26730 | } |
| 26641 | 26731 | union_obj.status = .have_layout; |
| 26642 | 26732 | } |
| ... | ... | @@ -26764,12 +26854,12 @@ pub fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) |
| 26764 | 26854 | switch (ty.tag()) { |
| 26765 | 26855 | .@"struct" => { |
| 26766 | 26856 | const struct_obj = ty.castTag(.@"struct").?.data; |
| 26767 | | try sema.resolveTypeFieldsStruct(block, src, ty, struct_obj); |
| 26857 | try sema.resolveTypeFieldsStruct(ty, struct_obj); |
| 26768 | 26858 | return ty; |
| 26769 | 26859 | }, |
| 26770 | 26860 | .@"union", .union_safety_tagged, .union_tagged => { |
| 26771 | 26861 | const union_obj = ty.cast(Type.Payload.Union).?.data; |
| 26772 | | try sema.resolveTypeFieldsUnion(block, src, ty, union_obj); |
| 26862 | try sema.resolveTypeFieldsUnion(ty, union_obj); |
| 26773 | 26863 | return ty; |
| 26774 | 26864 | }, |
| 26775 | 26865 | .type_info => return sema.resolveBuiltinTypeFields(block, src, "Type"), |
| ... | ... | @@ -26790,15 +26880,19 @@ pub fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) |
| 26790 | 26880 | |
| 26791 | 26881 | fn resolveTypeFieldsStruct( |
| 26792 | 26882 | sema: *Sema, |
| 26793 | | block: *Block, |
| 26794 | | src: LazySrcLoc, |
| 26795 | 26883 | ty: Type, |
| 26796 | 26884 | struct_obj: *Module.Struct, |
| 26797 | 26885 | ) CompileError!void { |
| 26798 | 26886 | switch (struct_obj.status) { |
| 26799 | 26887 | .none => {}, |
| 26800 | 26888 | .field_types_wip => { |
| 26801 | | return sema.fail(block, src, "struct '{}' depends on itself", .{ty.fmt(sema.mod)}); |
| 26889 | const msg = try Module.ErrorMsg.create( |
| 26890 | sema.gpa, |
| 26891 | struct_obj.srcLoc(sema.mod), |
| 26892 | "struct '{}' depends on itself", |
| 26893 | .{ty.fmt(sema.mod)}, |
| 26894 | ); |
| 26895 | return sema.failWithOwnedErrorMsg(msg); |
| 26802 | 26896 | }, |
| 26803 | 26897 | .have_field_types, |
| 26804 | 26898 | .have_layout, |
| ... | ... | @@ -26812,17 +26906,17 @@ fn resolveTypeFieldsStruct( |
| 26812 | 26906 | try semaStructFields(sema.mod, struct_obj); |
| 26813 | 26907 | } |
| 26814 | 26908 | |
| 26815 | | fn resolveTypeFieldsUnion( |
| 26816 | | sema: *Sema, |
| 26817 | | block: *Block, |
| 26818 | | src: LazySrcLoc, |
| 26819 | | ty: Type, |
| 26820 | | union_obj: *Module.Union, |
| 26821 | | ) CompileError!void { |
| 26909 | fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_obj: *Module.Union) CompileError!void { |
| 26822 | 26910 | switch (union_obj.status) { |
| 26823 | 26911 | .none => {}, |
| 26824 | 26912 | .field_types_wip => { |
| 26825 | | return sema.fail(block, src, "union '{}' depends on itself", .{ty.fmt(sema.mod)}); |
| 26913 | const msg = try Module.ErrorMsg.create( |
| 26914 | sema.gpa, |
| 26915 | union_obj.srcLoc(sema.mod), |
| 26916 | "union '{}' depends on itself", |
| 26917 | .{ty.fmt(sema.mod)}, |
| 26918 | ); |
| 26919 | return sema.failWithOwnedErrorMsg(msg); |
| 26826 | 26920 | }, |
| 26827 | 26921 | .have_field_types, |
| 26828 | 26922 | .have_layout, |
| ... | ... | @@ -27038,7 +27132,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 27038 | 27132 | try sema.errNote(&block_scope, src, msg, "struct declared here", .{}); |
| 27039 | 27133 | break :msg msg; |
| 27040 | 27134 | }; |
| 27041 | | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 27135 | return sema.failWithOwnedErrorMsg(msg); |
| 27042 | 27136 | } |
| 27043 | 27137 | gop.value_ptr.* = .{ |
| 27044 | 27138 | .ty = Type.initTag(.noreturn), |
| ... | ... | @@ -27097,7 +27191,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 27097 | 27191 | try sema.addDeclaredHereNote(msg, field_ty); |
| 27098 | 27192 | break :msg msg; |
| 27099 | 27193 | }; |
| 27100 | | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 27194 | return sema.failWithOwnedErrorMsg(msg); |
| 27101 | 27195 | } |
| 27102 | 27196 | if (struct_obj.layout == .Extern and !sema.validateExternType(field.ty, .other)) { |
| 27103 | 27197 | const msg = msg: { |
| ... | ... | @@ -27111,7 +27205,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 27111 | 27205 | try sema.addDeclaredHereNote(msg, field.ty); |
| 27112 | 27206 | break :msg msg; |
| 27113 | 27207 | }; |
| 27114 | | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 27208 | return sema.failWithOwnedErrorMsg(msg); |
| 27115 | 27209 | } else if (struct_obj.layout == .Packed and !(validatePackedType(field.ty))) { |
| 27116 | 27210 | const msg = msg: { |
| 27117 | 27211 | const tree = try sema.getAstTree(&block_scope); |
| ... | ... | @@ -27124,7 +27218,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 27124 | 27218 | try sema.addDeclaredHereNote(msg, field.ty); |
| 27125 | 27219 | break :msg msg; |
| 27126 | 27220 | }; |
| 27127 | | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 27221 | return sema.failWithOwnedErrorMsg(msg); |
| 27128 | 27222 | } |
| 27129 | 27223 | |
| 27130 | 27224 | if (zir_field.align_body_len > 0) { |
| ... | ... | @@ -27406,7 +27500,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 27406 | 27500 | try sema.errNote(&block_scope, src, msg, "union declared here", .{}); |
| 27407 | 27501 | break :msg msg; |
| 27408 | 27502 | }; |
| 27409 | | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 27503 | return sema.failWithOwnedErrorMsg(msg); |
| 27410 | 27504 | } |
| 27411 | 27505 | |
| 27412 | 27506 | if (tag_ty_field_names) |*names| { |
| ... | ... | @@ -27420,7 +27514,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 27420 | 27514 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| 27421 | 27515 | break :msg msg; |
| 27422 | 27516 | }; |
| 27423 | | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 27517 | return sema.failWithOwnedErrorMsg(msg); |
| 27424 | 27518 | } |
| 27425 | 27519 | } |
| 27426 | 27520 | |
| ... | ... | @@ -27434,7 +27528,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 27434 | 27528 | try sema.addDeclaredHereNote(msg, field_ty); |
| 27435 | 27529 | break :msg msg; |
| 27436 | 27530 | }; |
| 27437 | | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 27531 | return sema.failWithOwnedErrorMsg(msg); |
| 27438 | 27532 | } |
| 27439 | 27533 | if (union_obj.layout == .Extern and !sema.validateExternType(field_ty, .union_field)) { |
| 27440 | 27534 | const msg = msg: { |
| ... | ... | @@ -27448,7 +27542,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 27448 | 27542 | try sema.addDeclaredHereNote(msg, field_ty); |
| 27449 | 27543 | break :msg msg; |
| 27450 | 27544 | }; |
| 27451 | | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 27545 | return sema.failWithOwnedErrorMsg(msg); |
| 27452 | 27546 | } else if (union_obj.layout == .Packed and !(validatePackedType(field_ty))) { |
| 27453 | 27547 | const msg = msg: { |
| 27454 | 27548 | const tree = try sema.getAstTree(&block_scope); |
| ... | ... | @@ -27461,7 +27555,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 27461 | 27555 | try sema.addDeclaredHereNote(msg, field_ty); |
| 27462 | 27556 | break :msg msg; |
| 27463 | 27557 | }; |
| 27464 | | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 27558 | return sema.failWithOwnedErrorMsg(msg); |
| 27465 | 27559 | } |
| 27466 | 27560 | |
| 27467 | 27561 | gop.value_ptr.* = .{ |
| ... | ... | @@ -27493,7 +27587,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 27493 | 27587 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| 27494 | 27588 | break :msg msg; |
| 27495 | 27589 | }; |
| 27496 | | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 27590 | return sema.failWithOwnedErrorMsg(msg); |
| 27497 | 27591 | } |
| 27498 | 27592 | } |
| 27499 | 27593 | } |
| ... | ... | @@ -27756,9 +27850,19 @@ pub fn typeHasOnePossibleValue( |
| 27756 | 27850 | .@"struct" => { |
| 27757 | 27851 | const resolved_ty = try sema.resolveTypeFields(block, src, ty); |
| 27758 | 27852 | const s = resolved_ty.castTag(.@"struct").?.data; |
| 27759 | | for (s.fields.values()) |value| { |
| 27760 | | if (value.is_comptime) continue; |
| 27761 | | if ((try sema.typeHasOnePossibleValue(block, src, value.ty)) == null) { |
| 27853 | for (s.fields.values()) |field, i| { |
| 27854 | if (field.is_comptime) continue; |
| 27855 | if (field.ty.eql(resolved_ty, sema.mod)) { |
| 27856 | const msg = try Module.ErrorMsg.create( |
| 27857 | sema.gpa, |
| 27858 | s.srcLoc(sema.mod), |
| 27859 | "struct '{}' depends on itself", |
| 27860 | .{ty.fmt(sema.mod)}, |
| 27861 | ); |
| 27862 | try sema.addFieldErrNote(block, resolved_ty, i, msg, "while checking this field", .{}); |
| 27863 | return sema.failWithOwnedErrorMsg(msg); |
| 27864 | } |
| 27865 | if ((try sema.typeHasOnePossibleValue(block, src, field.ty)) == null) { |
| 27762 | 27866 | return null; |
| 27763 | 27867 | } |
| 27764 | 27868 | } |
| ... | ... | @@ -27824,6 +27928,16 @@ pub fn typeHasOnePossibleValue( |
| 27824 | 27928 | const tag_val = (try sema.typeHasOnePossibleValue(block, src, union_obj.tag_ty)) orelse |
| 27825 | 27929 | return null; |
| 27826 | 27930 | const only_field = union_obj.fields.values()[0]; |
| 27931 | if (only_field.ty.eql(resolved_ty, sema.mod)) { |
| 27932 | const msg = try Module.ErrorMsg.create( |
| 27933 | sema.gpa, |
| 27934 | union_obj.srcLoc(sema.mod), |
| 27935 | "union '{}' depends on itself", |
| 27936 | .{ty.fmt(sema.mod)}, |
| 27937 | ); |
| 27938 | try sema.addFieldErrNote(block, resolved_ty, 0, msg, "while checking this field", .{}); |
| 27939 | return sema.failWithOwnedErrorMsg(msg); |
| 27940 | } |
| 27827 | 27941 | const val_val = (try sema.typeHasOnePossibleValue(block, src, only_field.ty)) orelse |
| 27828 | 27942 | return null; |
| 27829 | 27943 | // TODO make this not allocate. The function in `Type.onePossibleValue` |
| ... | ... | @@ -28463,7 +28577,7 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ |
| 28463 | 28577 | if (struct_obj.status == .field_types_wip) |
| 28464 | 28578 | return false; |
| 28465 | 28579 | |
| 28466 | | try sema.resolveTypeFieldsStruct(block, src, ty, struct_obj); |
| 28580 | try sema.resolveTypeFieldsStruct(ty, struct_obj); |
| 28467 | 28581 | |
| 28468 | 28582 | struct_obj.requires_comptime = .wip; |
| 28469 | 28583 | for (struct_obj.fields.values()) |field| { |
| ... | ... | @@ -28488,7 +28602,7 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ |
| 28488 | 28602 | if (union_obj.status == .field_types_wip) |
| 28489 | 28603 | return false; |
| 28490 | 28604 | |
| 28491 | | try sema.resolveTypeFieldsUnion(block, src, ty, union_obj); |
| 28605 | try sema.resolveTypeFieldsUnion(ty, union_obj); |
| 28492 | 28606 | |
| 28493 | 28607 | union_obj.requires_comptime = .wip; |
| 28494 | 28608 | for (union_obj.fields.values()) |field| { |