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 {...@@ -11761,9 +11761,9 @@ const GenZir = struct {
11761 ) !Zir.Inst.Index {11761 ) !Zir.Inst.Index {
11762 const gpa = gz.astgen.gpa;11762 const gpa = gz.astgen.gpa;
11763 const param_body = param_gz.instructionsSlice();11763 const param_body = param_gz.instructionsSlice();
11764 const body_len = gz.astgen.countBodyLenAfterFixups(param_body);
11764 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);11765 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
11765 try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Param).Struct.fields.len +11766 try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Param).Struct.fields.len + body_len);
11766 param_body.len);
1176711767
11768 const doc_comment_index = if (first_doc_comment) |first|11768 const doc_comment_index = if (first_doc_comment) |first|
11769 try gz.astgen.docCommentAsStringFromFirst(abs_tok_index, first)11769 try gz.astgen.docCommentAsStringFromFirst(abs_tok_index, first)
...@@ -11773,9 +11773,9 @@ const GenZir = struct {...@@ -11773,9 +11773,9 @@ const GenZir = struct {
11773 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{11773 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{
11774 .name = name,11774 .name = name,
11775 .doc_comment = doc_comment_index,11775 .doc_comment = doc_comment_index,
11776 .body_len = @intCast(u32, param_body.len),11776 .body_len = @intCast(u32, body_len),
11777 });11777 });
11778 gz.astgen.extra.appendSliceAssumeCapacity(param_body);11778 gz.astgen.appendBodyWithFixups(param_body);
11779 param_gz.unstack();11779 param_gz.unstack();
1178011780
11781 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);11781 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" {...@@ -415,3 +415,16 @@ test "inline while with @call" {
415 }415 }
416 try expect(a == 10);416 try expect(a == 10);
417}417}
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}