From 26064984097889353dda38423ac8b876f373526f Mon Sep 17 00:00:00 2001 From: John Schmidt Date: Sun, 7 May 2023 22:58:15 +0200 Subject: [PATCH] module: return null if no candidate src Closes #15572. --- src/Module.zig | 2 ++ .../issue_15572_break_on_inline_while.zig | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 test/cases/compile_errors/issue_15572_break_on_inline_while.zig diff --git a/src/Module.zig b/src/Module.zig index 6a33990463..b0c18def78 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -6115,6 +6115,8 @@ pub const PeerTypeCandidateSrc = union(enum) { return null; }, .override => |candidate_srcs| { + if (candidate_i >= candidate_srcs.len) + return null; return candidate_srcs[candidate_i]; }, .typeof_builtin_call_node_offset => |node_offset| { diff --git a/test/cases/compile_errors/issue_15572_break_on_inline_while.zig b/test/cases/compile_errors/issue_15572_break_on_inline_while.zig new file mode 100644 index 0000000000..a09a72fde5 --- /dev/null +++ b/test/cases/compile_errors/issue_15572_break_on_inline_while.zig @@ -0,0 +1,20 @@ +const std = @import("std"); + +pub const DwarfSection = enum { + eh_frame, + eh_frame_hdr, +}; + +pub fn main() void { + const section = inline for (@typeInfo(DwarfSection).Enum.fields) |section| { + if (std.mem.eql(u8, section.name, "eh_frame")) break section; + }; + + _ = section; +} + +// error +// backend=stage2 +// target=native +// +// :9:28: error: incompatible types: 'builtin.Type.EnumField' and 'void'