From bf4b43a2f7257c3beb202790551a1312e4dd40b1 Mon Sep 17 00:00:00 2001 From: mlugg Date: Sat, 10 Jun 2023 00:26:23 +0100 Subject: [PATCH] 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 --- src/AstGen.zig | 8 ++++---- test/behavior/call.zig | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index f8bb24c14d..b38067fd03 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -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); diff --git a/test/behavior/call.zig b/test/behavior/call.zig index c1bd1ae76d..4645a2ad9e 100644 --- a/test/behavior/call.zig +++ b/test/behavior/call.zig @@ -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)); +}