| ... | ... | @@ -17961,20 +17961,21 @@ fn finishStructInit( |
| 17961 | 17961 | return sema.failWithOwnedErrorMsg(msg); |
| 17962 | 17962 | } |
| 17963 | 17963 | |
| 17964 | | const is_comptime = for (field_inits) |field_init| { |
| 17964 | // Find which field forces the expression to be runtime, if any. |
| 17965 | const opt_runtime_index = for (field_inits, 0..) |field_init, i| { |
| 17965 | 17966 | if (!(try sema.isComptimeKnown(field_init))) { |
| 17966 | | break false; |
| 17967 | break i; |
| 17967 | 17968 | } |
| 17968 | | } else true; |
| 17969 | } else null; |
| 17969 | 17970 | |
| 17970 | | if (is_comptime) { |
| 17971 | const runtime_index = opt_runtime_index orelse { |
| 17971 | 17972 | const values = try sema.arena.alloc(Value, field_inits.len); |
| 17972 | 17973 | for (field_inits, 0..) |field_init, i| { |
| 17973 | 17974 | values[i] = (sema.resolveMaybeUndefVal(field_init) catch unreachable).?; |
| 17974 | 17975 | } |
| 17975 | 17976 | const struct_val = try Value.Tag.aggregate.create(sema.arena, values); |
| 17976 | 17977 | return sema.addConstantMaybeRef(block, struct_ty, struct_val, is_ref); |
| 17977 | | } |
| 17978 | }; |
| 17978 | 17979 | |
| 17979 | 17980 | if (is_ref) { |
| 17980 | 17981 | try sema.resolveStructLayout(struct_ty); |
| ... | ... | @@ -17994,7 +17995,15 @@ fn finishStructInit( |
| 17994 | 17995 | return sema.makePtrConst(block, alloc); |
| 17995 | 17996 | } |
| 17996 | 17997 | |
| 17997 | | try sema.requireRuntimeBlock(block, dest_src, null); |
| 17998 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { |
| 17999 | error.NeededSourceLocation => { |
| 18000 | const decl = sema.mod.declPtr(block.src_decl); |
| 18001 | const field_src = Module.initSrc(dest_src.node_offset.x, sema.gpa, decl, runtime_index); |
| 18002 | try sema.requireRuntimeBlock(block, dest_src, field_src); |
| 18003 | unreachable; |
| 18004 | }, |
| 18005 | else => |e| return e, |
| 18006 | }; |
| 17998 | 18007 | try sema.queueFullTypeResolution(struct_ty); |
| 17999 | 18008 | return block.addAggregateInit(struct_ty, field_inits); |
| 18000 | 18009 | } |
| ... | ... | @@ -18014,6 +18023,7 @@ fn zirStructInitAnon( |
| 18014 | 18023 | defer fields.deinit(sema.gpa); |
| 18015 | 18024 | try fields.ensureUnusedCapacity(sema.gpa, types.len); |
| 18016 | 18025 | |
| 18026 | // Find which field forces the expression to be runtime, if any. |
| 18017 | 18027 | const opt_runtime_index = rs: { |
| 18018 | 18028 | var runtime_index: ?usize = null; |
| 18019 | 18029 | var extra_index = extra.end; |