mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
stage2: save and restore parameters when resolving inline bodies
This caused zirParam instructions of parent blocks to be present in inline analyzed blocks, and so function prototypes declared in the inline blocks would also gain and add to the parameters in the parent block. Only block and block_inline are affected in this commit, as prototypes and declarations are always generated in block_inline. This might need to be resolved in a more general way at some point.
This commit is contained in:
parent
e18c3f3109
commit
d5621504b0
18
src/Sema.zig
18
src/Sema.zig
@ -940,6 +940,15 @@ pub fn analyzeBody(
|
||||
const inst_data = datas[inst].pl_node;
|
||||
const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
|
||||
const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len];
|
||||
// If this block contains a function prototype, we need to reset the
|
||||
// current list of parameters and restore it later.
|
||||
// Note: this probably needs to be resolved in a more general manner.
|
||||
const prev_params = block.params;
|
||||
block.params = .{};
|
||||
defer {
|
||||
block.params.deinit(sema.gpa);
|
||||
block.params = prev_params;
|
||||
}
|
||||
const break_inst = try sema.analyzeBody(block, inline_body);
|
||||
const break_data = datas[break_inst].@"break";
|
||||
if (inst == break_data.block_inst) {
|
||||
@ -953,6 +962,15 @@ pub fn analyzeBody(
|
||||
const inst_data = datas[inst].pl_node;
|
||||
const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
|
||||
const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len];
|
||||
// If this block contains a function prototype, we need to reset the
|
||||
// current list of parameters and restore it later.
|
||||
// Note: this probably needs to be resolved in a more general manner.
|
||||
const prev_params = block.params;
|
||||
block.params = .{};
|
||||
defer {
|
||||
block.params.deinit(sema.gpa);
|
||||
block.params = prev_params;
|
||||
}
|
||||
const break_inst = try sema.analyzeBody(block, inline_body);
|
||||
const break_data = datas[break_inst].@"break";
|
||||
if (inst == break_data.block_inst) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user