AstGen: handle ref_table for params

This is kind of similar to 1a4b0d9. In this case, we need to handle
ref_table when appending the body of param instructions.

Resolves: #15952
This commit is contained in:
mlugg 2023-06-10 00:26:23 +01:00 committed by Veikka Tuominen
parent 2094d98694
commit bf4b43a2f7
2 changed files with 17 additions and 4 deletions

View File

@ -11761,9 +11761,9 @@ const GenZir = struct {
) !Zir.Inst.Index {
const gpa = gz.astgen.gpa;
const param_body = param_gz.instructionsSlice();
const body_len = gz.astgen.countBodyLenAfterFixups(param_body);
try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Param).Struct.fields.len +
param_body.len);
try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Param).Struct.fields.len + body_len);
const doc_comment_index = if (first_doc_comment) |first|
try gz.astgen.docCommentAsStringFromFirst(abs_tok_index, first)
@ -11773,9 +11773,9 @@ const GenZir = struct {
const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{
.name = name,
.doc_comment = doc_comment_index,
.body_len = @intCast(u32, param_body.len),
.body_len = @intCast(u32, body_len),
});
gz.astgen.extra.appendSliceAssumeCapacity(param_body);
gz.astgen.appendBodyWithFixups(param_body);
param_gz.unstack();
const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);

View File

@ -415,3 +415,16 @@ test "inline while with @call" {
}
try expect(a == 10);
}
test "method call as parameter type" {
const S = struct {
fn foo(x: anytype, y: @TypeOf(x).Inner()) @TypeOf(y) {
return y;
}
fn Inner() type {
return u64;
}
};
try expectEqual(@as(u64, 123), S.foo(S{}, 123));
try expectEqual(@as(u64, 500), S.foo(S{}, 500));
}