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