| ... | @@ -8197,7 +8197,6 @@ fn zirSwitchCapture( | ... | @@ -8197,7 +8197,6 @@ fn zirSwitchCapture( |
| 8197 | const switch_info = zir_datas[capture_info.switch_inst].pl_node; | 8197 | const switch_info = zir_datas[capture_info.switch_inst].pl_node; |
| 8198 | const switch_extra = sema.code.extraData(Zir.Inst.SwitchBlock, switch_info.payload_index); | 8198 | const switch_extra = sema.code.extraData(Zir.Inst.SwitchBlock, switch_info.payload_index); |
| 8199 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_info.src_node }; | 8199 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_info.src_node }; |
| 8200 | const switch_src = switch_info.src(); | | |
| 8201 | const operand_is_ref = switch_extra.data.bits.is_ref; | 8200 | const operand_is_ref = switch_extra.data.bits.is_ref; |
| 8202 | const cond_inst = Zir.refToIndex(switch_extra.data.operand).?; | 8201 | const cond_inst = Zir.refToIndex(switch_extra.data.operand).?; |
| 8203 | const cond_info = sema.code.instructions.items(.data)[cond_inst].un_node; | 8202 | const cond_info = sema.code.instructions.items(.data)[cond_inst].un_node; |
| ... | @@ -8247,7 +8246,7 @@ fn zirSwitchCapture( | ... | @@ -8247,7 +8246,7 @@ fn zirSwitchCapture( |
| 8247 | const first_field_index = @intCast(u32, enum_ty.enumTagFieldIndex(first_item_val, sema.mod).?); | 8246 | const first_field_index = @intCast(u32, enum_ty.enumTagFieldIndex(first_item_val, sema.mod).?); |
| 8248 | const first_field = union_obj.fields.values()[first_field_index]; | 8247 | const first_field = union_obj.fields.values()[first_field_index]; |
| 8249 | | 8248 | |
| 8250 | for (items[1..]) |item| { | 8249 | for (items[1..]) |item, i| { |
| 8251 | const item_ref = try sema.resolveInst(item); | 8250 | const item_ref = try sema.resolveInst(item); |
| 8252 | // Previous switch validation ensured this will succeed | 8251 | // Previous switch validation ensured this will succeed |
| 8253 | const item_val = sema.resolveConstValue(block, .unneeded, item_ref, undefined) catch unreachable; | 8252 | const item_val = sema.resolveConstValue(block, .unneeded, item_ref, undefined) catch unreachable; |
| ... | @@ -8255,11 +8254,17 @@ fn zirSwitchCapture( | ... | @@ -8255,11 +8254,17 @@ fn zirSwitchCapture( |
| 8255 | const field_index = enum_ty.enumTagFieldIndex(item_val, sema.mod).?; | 8254 | const field_index = enum_ty.enumTagFieldIndex(item_val, sema.mod).?; |
| 8256 | const field = union_obj.fields.values()[field_index]; | 8255 | const field = union_obj.fields.values()[field_index]; |
| 8257 | if (!field.ty.eql(first_field.ty, sema.mod)) { | 8256 | if (!field.ty.eql(first_field.ty, sema.mod)) { |
| 8258 | const first_item_src = switch_src; // TODO better source location | | |
| 8259 | const item_src = switch_src; | | |
| 8260 | const msg = msg: { | 8257 | const msg = msg: { |
| 8261 | const msg = try sema.errMsg(block, switch_src, "capture group with incompatible types", .{}); | 8258 | const raw_capture_src = Module.SwitchProngSrc{ .multi_capture = capture_info.prong_index }; |
| | 8259 | const capture_src = raw_capture_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first); |
| | 8260 | |
| | 8261 | const msg = try sema.errMsg(block, capture_src, "capture group with incompatible types", .{}); |
| 8262 | errdefer msg.destroy(sema.gpa); | 8262 | errdefer msg.destroy(sema.gpa); |
| | 8263 | |
| | 8264 | const raw_first_item_src = Module.SwitchProngSrc{ .multi = .{ .prong = capture_info.prong_index, .item = 0 } }; |
| | 8265 | const first_item_src = raw_first_item_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first); |
| | 8266 | const raw_item_src = Module.SwitchProngSrc{ .multi = .{ .prong = capture_info.prong_index, .item = 1 + @intCast(u32, i) } }; |
| | 8267 | const item_src = raw_item_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first); |
| 8263 | try sema.errNote(block, first_item_src, msg, "type '{}' here", .{first_field.ty.fmt(sema.mod)}); | 8268 | try sema.errNote(block, first_item_src, msg, "type '{}' here", .{first_field.ty.fmt(sema.mod)}); |
| 8264 | try sema.errNote(block, item_src, msg, "type '{}' here", .{field.ty.fmt(sema.mod)}); | 8269 | try sema.errNote(block, item_src, msg, "type '{}' here", .{field.ty.fmt(sema.mod)}); |
| 8265 | break :msg msg; | 8270 | break :msg msg; |
| ... | @@ -21094,17 +21099,17 @@ const InMemoryCoercionResult = union(enum) { | ... | @@ -21094,17 +21099,17 @@ const InMemoryCoercionResult = union(enum) { |
| 21094 | } | 21099 | } |
| 21095 | } | 21100 | } |
| 21096 | if (!actual_noalias) { | 21101 | if (!actual_noalias) { |
| 21097 | try sema.errNote(block, src, msg, "regular paramter {d} cannot cast into a noalias paramter", .{index}); | 21102 | try sema.errNote(block, src, msg, "regular parameter {d} cannot cast into a noalias parameter", .{index}); |
| 21098 | } else { | 21103 | } else { |
| 21099 | try sema.errNote(block, src, msg, "noalias paramter {d} cannot cast into a regular paramter", .{index}); | 21104 | try sema.errNote(block, src, msg, "noalias parameter {d} cannot cast into a regular parameter", .{index}); |
| 21100 | } | 21105 | } |
| 21101 | break; | 21106 | break; |
| 21102 | }, | 21107 | }, |
| 21103 | .fn_param_comptime => |param| { | 21108 | .fn_param_comptime => |param| { |
| 21104 | if (param.wanted) { | 21109 | if (param.wanted) { |
| 21105 | try sema.errNote(block, src, msg, "non-comptime paramter {d} cannot cast into a comptime paramter", .{param.index}); | 21110 | try sema.errNote(block, src, msg, "non-comptime parameter {d} cannot cast into a comptime parameter", .{param.index}); |
| 21106 | } else { | 21111 | } else { |
| 21107 | try sema.errNote(block, src, msg, "comptime paramter {d} cannot cast into a non-comptime paramter", .{param.index}); | 21112 | try sema.errNote(block, src, msg, "comptime parameter {d} cannot cast into a non-comptime parameter", .{param.index}); |
| 21108 | } | 21113 | } |
| 21109 | break; | 21114 | break; |
| 21110 | }, | 21115 | }, |