| ... | @@ -11186,14 +11186,8 @@ fn validateSwitchBlock( | ... | @@ -11186,14 +11186,8 @@ fn validateSwitchBlock( |
| 11186 | operand_ty.assertHasLayout(zcu); | 11186 | operand_ty.assertHasLayout(zcu); |
| 11187 | const union_obj = ip.loadUnionType(operand_ty.toIntern()); | 11187 | const union_obj = ip.loadUnionType(operand_ty.toIntern()); |
| 11188 | switch (union_obj.tag_usage) { | 11188 | switch (union_obj.tag_usage) { |
| 11189 | .tagged => { | 11189 | .tagged => break :item_ty .fromInterned(union_obj.enum_tag_type), |
| 11190 | break :item_ty .fromInterned(union_obj.enum_tag_type); | 11190 | .none => if (union_obj.layout == .@"packed") break :item_ty operand_ty, |
| 11191 | }, | | |
| 11192 | .none => { | | |
| 11193 | if (union_obj.layout == .@"packed") { | | |
| 11194 | break :item_ty operand_ty; | | |
| 11195 | } | | |
| 11196 | }, | | |
| 11197 | .safety => {}, | 11191 | .safety => {}, |
| 11198 | } | 11192 | } |
| 11199 | return sema.failWithOwnedErrorMsg(block, msg: { | 11193 | return sema.failWithOwnedErrorMsg(block, msg: { |
| ... | @@ -11208,27 +11202,47 @@ fn validateSwitchBlock( | ... | @@ -11208,27 +11202,47 @@ fn validateSwitchBlock( |
| 11208 | | 11202 | |
| 11209 | .@"struct" => { | 11203 | .@"struct" => { |
| 11210 | operand_ty.assertHasLayout(zcu); | 11204 | operand_ty.assertHasLayout(zcu); |
| 11211 | const layout = operand_ty.containerLayout(zcu); | 11205 | if (operand_ty.containerLayout(zcu) == .@"packed") break :item_ty operand_ty; |
| 11212 | if (layout == .@"packed") { | | |
| 11213 | break :item_ty operand_ty; | | |
| 11214 | } | | |
| 11215 | return sema.failWithOwnedErrorMsg(block, msg: { | 11206 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 11216 | const msg = try sema.errMsg(operand_src, "switch on struct with {t} layout", .{layout}); | 11207 | const msg = try sema.errMsg(operand_src, "switch on non-packed struct", .{}); |
| 11217 | errdefer msg.destroy(sema.gpa); | 11208 | errdefer msg.destroy(sema.gpa); |
| 11218 | if (operand_ty.srcLocOrNull(zcu)) |struct_src| { | 11209 | try sema.addDeclaredHereNote(msg, operand_ty); |
| 11219 | try sema.errNote(struct_src, msg, "consider 'packed struct' here", .{}); | | |
| 11220 | } | | |
| 11221 | break :msg msg; | 11210 | break :msg msg; |
| 11222 | }); | 11211 | }); |
| 11223 | }, | 11212 | }, |
| 11224 | | 11213 | |
| 11225 | .pointer => { | 11214 | .pointer => if (!operand_ty.isSlice(zcu)) break :item_ty operand_ty, |
| 11226 | if (!operand_ty.isSlice(zcu)) { | | |
| 11227 | break :item_ty operand_ty; | | |
| 11228 | } | | |
| 11229 | }, | | |
| 11230 | | 11215 | |
| 11231 | else => {}, | 11216 | .optional => return sema.failWithOwnedErrorMsg(block, msg: { |
| | 11217 | const msg = try sema.errMsg(operand_src, "switch on optional type '{f}'", .{ |
| | 11218 | operand_ty.fmt(pt), |
| | 11219 | }); |
| | 11220 | errdefer msg.destroy(gpa); |
| | 11221 | try sema.errNote(operand_src, msg, "consider using '.?', 'orelse', or 'if'", .{}); |
| | 11222 | break :msg msg; |
| | 11223 | }), |
| | 11224 | |
| | 11225 | .error_union => return sema.failWithOwnedErrorMsg(block, msg: { |
| | 11226 | const msg = try sema.errMsg(operand_src, "switch on error union type '{f}'", .{ |
| | 11227 | operand_ty.fmt(pt), |
| | 11228 | }); |
| | 11229 | errdefer msg.destroy(gpa); |
| | 11230 | try sema.errNote(operand_src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| | 11231 | break :msg msg; |
| | 11232 | }), |
| | 11233 | |
| | 11234 | .noreturn, |
| | 11235 | .float, |
| | 11236 | .comptime_float, |
| | 11237 | .array, |
| | 11238 | .vector, |
| | 11239 | .undefined, |
| | 11240 | .null, |
| | 11241 | .@"opaque", |
| | 11242 | .frame, |
| | 11243 | .@"anyframe", |
| | 11244 | .spirv, |
| | 11245 | => {}, |
| 11232 | } | 11246 | } |
| 11233 | return sema.fail(block, operand_src, "switch on type '{f}'", .{operand_ty.fmt(pt)}); | 11247 | return sema.fail(block, operand_src, "switch on type '{f}'", .{operand_ty.fmt(pt)}); |
| 11234 | }; | 11248 | }; |