| ... | ... | @@ -10924,50 +10924,51 @@ const SwitchProngAnalysis = struct { |
| 10924 | 10924 | // By-reference captures have some further restrictions which make them easier to emit |
| 10925 | 10925 | if (capture_byref) { |
| 10926 | 10926 | const operand_ptr_info = operand_ptr_ty.ptrInfo(mod); |
| 10927 | | const capture_ptr_ty = try sema.ptrType(.{ |
| 10928 | | .child = capture_ty.toIntern(), |
| 10929 | | .flags = .{ |
| 10930 | | // TODO: alignment! |
| 10931 | | .is_const = operand_ptr_info.flags.is_const, |
| 10932 | | .is_volatile = operand_ptr_info.flags.is_volatile, |
| 10933 | | .address_space = operand_ptr_info.flags.address_space, |
| 10934 | | }, |
| 10935 | | }); |
| 10936 | | |
| 10937 | | // By-ref captures of hetereogeneous types are only allowed if each field |
| 10938 | | // pointer type is in-memory coercible to the capture pointer type. |
| 10939 | | if (!same_types) { |
| 10940 | | for (field_indices, 0..) |field_idx, i| { |
| 10927 | const capture_ptr_ty = resolve: { |
| 10928 | // By-ref captures of hetereogeneous types are only allowed if all field |
| 10929 | // pointer types are peer resolvable to each other. |
| 10930 | // We need values to run PTR on, so make a bunch of undef constants. |
| 10931 | const dummy_captures = try sema.arena.alloc(Air.Inst.Ref, case_vals.len); |
| 10932 | for (field_indices, dummy_captures) |field_idx, *dummy| { |
| 10941 | 10933 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]); |
| 10942 | 10934 | const field_ptr_ty = try sema.ptrType(.{ |
| 10943 | 10935 | .child = field_ty.toIntern(), |
| 10944 | 10936 | .flags = .{ |
| 10945 | | // TODO: alignment! |
| 10946 | 10937 | .is_const = operand_ptr_info.flags.is_const, |
| 10947 | 10938 | .is_volatile = operand_ptr_info.flags.is_volatile, |
| 10948 | 10939 | .address_space = operand_ptr_info.flags.address_space, |
| 10940 | .alignment = union_obj.fieldAlign(ip, field_idx), |
| 10949 | 10941 | }, |
| 10950 | 10942 | }); |
| 10951 | | if (.ok != try sema.coerceInMemoryAllowed(block, capture_ptr_ty, field_ptr_ty, false, sema.mod.getTarget(), .unneeded, .unneeded)) { |
| 10943 | dummy.* = try mod.undefRef(field_ptr_ty); |
| 10944 | } |
| 10945 | const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len); |
| 10946 | @memset(case_srcs, .unneeded); |
| 10947 | |
| 10948 | break :resolve sema.resolvePeerTypes(block, .unneeded, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) { |
| 10949 | error.NeededSourceLocation => { |
| 10950 | // This must be a multi-prong so this must be a `multi_capture` src |
| 10952 | 10951 | const multi_idx = raw_capture_src.multi_capture; |
| 10953 | 10952 | const src_decl_ptr = sema.mod.declPtr(block.src_decl); |
| 10953 | for (case_srcs, 0..) |*case_src, i| { |
| 10954 | const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } }; |
| 10955 | case_src.* = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none); |
| 10956 | } |
| 10954 | 10957 | const capture_src = raw_capture_src.resolve(mod, src_decl_ptr, switch_node_offset, .none); |
| 10955 | | const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } }; |
| 10956 | | const case_src = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none); |
| 10957 | | const msg = msg: { |
| 10958 | | const msg = try sema.errMsg(block, capture_src, "capture group with incompatible types", .{}); |
| 10959 | | errdefer msg.destroy(sema.gpa); |
| 10960 | | try sema.errNote(block, case_src, msg, "pointer type child '{}' cannot cast into resolved pointer type child '{}'", .{ |
| 10961 | | field_ty.fmt(sema.mod), |
| 10962 | | capture_ty.fmt(sema.mod), |
| 10963 | | }); |
| 10964 | | try sema.errNote(block, capture_src, msg, "this coercion is only possible when capturing by value", .{}); |
| 10965 | | break :msg msg; |
| 10958 | _ = sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err1| switch (err1) { |
| 10959 | error.AnalysisFail => { |
| 10960 | const msg = sema.err orelse return error.AnalysisFail; |
| 10961 | try sema.errNote(block, capture_src, msg, "this coercion is only possible when capturing by value", .{}); |
| 10962 | try sema.reparentOwnedErrorMsg(block, capture_src, msg, "capture group with incompatible types", .{}); |
| 10963 | return error.AnalysisFail; |
| 10964 | }, |
| 10965 | else => |e| return e, |
| 10966 | 10966 | }; |
| 10967 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 10968 | | } |
| 10969 | | } |
| 10970 | | } |
| 10967 | unreachable; |
| 10968 | }, |
| 10969 | else => |e| return e, |
| 10970 | }; |
| 10971 | }; |
| 10971 | 10972 | |
| 10972 | 10973 | if (try sema.resolveDefinedValue(block, operand_src, spa.operand_ptr)) |op_ptr_val| { |
| 10973 | 10974 | if (op_ptr_val.isUndef(mod)) return mod.undefRef(capture_ptr_ty); |