authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-06-10 00:26:23+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-06-10 07:18:05+03:00
logbf4b43a2f7257c3beb202790551a1312e4dd40b1
treef786070c2801a9483563dfd900fc88bb398c24d7
parent2094d98694b0336e2f37131abe34d0573b6b0633

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

2 files changed, 17 insertions(+), 4 deletions(-)

src/AstGen.zig+4-4
......@@ -11761,9 +11761,9 @@ const GenZir = struct {
1176111761 ) !Zir.Inst.Index {
1176211762 const gpa = gz.astgen.gpa;
1176311763 const param_body = param_gz.instructionsSlice();
11764 const body_len = gz.astgen.countBodyLenAfterFixups(param_body);
1176411765 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
11765 try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Param).Struct.fields.len +
11766 param_body.len);
11766 try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Param).Struct.fields.len + body_len);
1176711767
1176811768 const doc_comment_index = if (first_doc_comment) |first|
1176911769 try gz.astgen.docCommentAsStringFromFirst(abs_tok_index, first)
......@@ -11773,9 +11773,9 @@ const GenZir = struct {
1177311773 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{
1177411774 .name = name,
1177511775 .doc_comment = doc_comment_index,
11776 .body_len = @intCast(u32, param_body.len),
11776 .body_len = @intCast(u32, body_len),
1177711777 });
11778 gz.astgen.extra.appendSliceAssumeCapacity(param_body);
11778 gz.astgen.appendBodyWithFixups(param_body);
1177911779 param_gz.unstack();
1178011780
1178111781 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
test/behavior/call.zig+13
......@@ -415,3 +415,16 @@ test "inline while with @call" {
415415 }
416416 try expect(a == 10);
417417}
418
419test "method call as parameter type" {
420 const S = struct {
421 fn foo(x: anytype, y: @TypeOf(x).Inner()) @TypeOf(y) {
422 return y;
423 }
424 fn Inner() type {
425 return u64;
426 }
427 };
428 try expectEqual(@as(u64, 123), S.foo(S{}, 123));
429 try expectEqual(@as(u64, 500), S.foo(S{}, 500));
430}