authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-27 15:25:21+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-27 18:27:17+03:00
log793db63746ca044927743ee94405dad2a3f02fb8
treeeba9986d8448894a37a262b0f4f790818c02690e
parent3818d63dd8b29596e4c3d2499463b7519258a611

Sema: copy fn param ty in `zirTypeInfo`

Closes #12247

3 files changed, 30 insertions(+), 2 deletions(-)

src/Module.zig+10
......@@ -1220,6 +1220,7 @@ pub const Union = struct {
12201220 };
12211221 const node = owner_decl.relativeToNodeIndex(u.node_offset);
12221222 const node_tags = tree.nodes.items(.tag);
1223 var buf: [2]Ast.Node.Index = undefined;
12231224 switch (node_tags[node]) {
12241225 .container_decl,
12251226 .container_decl_trailing,
......@@ -1231,6 +1232,15 @@ pub const Union = struct {
12311232 .container_decl_arg,
12321233 .container_decl_arg_trailing,
12331234 => return queryFieldSrc(tree.*, query, file, tree.containerDeclArg(node)),
1235 .tagged_union,
1236 .tagged_union_trailing,
1237 => return queryFieldSrc(tree.*, query, file, tree.taggedUnion(node)),
1238 .tagged_union_two,
1239 .tagged_union_two_trailing,
1240 => return queryFieldSrc(tree.*, query, file, tree.taggedUnionTwo(&buf, node)),
1241 .tagged_union_enum_tag,
1242 .tagged_union_enum_tag_trailing,
1243 => return queryFieldSrc(tree.*, query, file, tree.taggedUnionEnumTag(node)),
12341244 else => unreachable,
12351245 }
12361246 }
src/Sema.zig+3-2
......@@ -5695,6 +5695,7 @@ fn analyzeCall(
56955695 sema.inst_map.clearRetainingCapacity();
56965696 const decl = sema.mod.declPtr(block.src_decl);
56975697 child_block.src_decl = block.src_decl;
5698 arg_i = 0;
56985699 try sema.analyzeInlineCallArg(
56995700 block,
57005701 &child_block,
......@@ -12864,7 +12865,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1286412865 else
1286512866 try Value.Tag.opt_payload.create(
1286612867 params_anon_decl.arena(),
12867 try Value.Tag.ty.create(params_anon_decl.arena(), param_ty),
12868 try Value.Tag.ty.create(params_anon_decl.arena(), try param_ty.copy(params_anon_decl.arena())),
1286812869 );
1286912870
1287012871 const param_fields = try params_anon_decl.arena().create([3]Value);
......@@ -26635,7 +26636,7 @@ fn getBuiltinType(
2663526636) CompileError!Type {
2663626637 const ty_inst = try sema.getBuiltin(block, src, name);
2663726638 const result_ty = try sema.analyzeAsType(block, src, ty_inst);
26638 try sema.queueFullTypeResolution(result_ty);
26639 try sema.resolveTypeFully(block, src, result_ty); // Should not fail
2663926640 return result_ty;
2664026641}
2664126642
test/cases/fn_typeinfo_passed_to_comptime_fn.zig created+17
......@@ -0,0 +1,17 @@
1const std = @import("std");
2
3test {
4 try foo(@typeInfo(@TypeOf(someFn)));
5}
6
7fn someFn(arg: ?*c_int) f64 {
8 _ = arg;
9 return 8;
10}
11fn foo(comptime info: std.builtin.Type) !void {
12 try std.testing.expect(info.Fn.args[0].arg_type.? == ?*c_int);
13}
14
15// run
16// is_test=1
17//