authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-03-17 13:21:43+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-03-17 13:33:05+02:00
logf983adfc1076adc8509458c4bb64102c797041ff
treec3f29f96fce9b11006e1d774b6f28ae160c6d632
parent294f51814f491ae4a09348d9e7221ae3e550c16f

Sema: fix printing of inferred error set of generic fn

Closes #19332

4 files changed, 24 insertions(+), 4 deletions(-)

src/Module.zig+5-2
...@@ -1897,8 +1897,11 @@ pub const SrcLoc = struct {...@@ -1897,8 +1897,11 @@ pub const SrcLoc = struct {
1897 const parent_node = src_loc.declRelativeToNodeIndex(node_off);1897 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
18981898
1899 var buf: [2]Ast.Node.Index = undefined;1899 var buf: [2]Ast.Node.Index = undefined;
1900 const full = tree.fullArrayInit(&buf, parent_node).?;1900 const type_expr = if (tree.fullArrayInit(&buf, parent_node)) |array_init|
1901 return tree.nodeToSpan(full.ast.type_expr);1901 array_init.ast.type_expr
1902 else
1903 tree.fullStructInit(&buf, parent_node).?.ast.type_expr;
1904 return tree.nodeToSpan(type_expr);
1902 },1905 },
1903 .node_offset_store_ptr => |node_off| {1906 .node_offset_store_ptr => |node_off| {
1904 const tree = try src_loc.file_scope.getTree(gpa);1907 const tree = try src_loc.file_scope.getTree(gpa);
src/Sema.zig+2-1
...@@ -19753,7 +19753,8 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -19753,7 +19753,8 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
1975319753
19754 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;19754 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
19755 const src = inst_data.src();19755 const src = inst_data.src();
19756 const obj_ty = try sema.resolveType(block, src, inst_data.operand);19756 const ty_src: LazySrcLoc = .{ .node_offset_init_ty = inst_data.src_node };
19757 const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand);
19757 const mod = sema.mod;19758 const mod = sema.mod;
1975819759
19759 switch (obj_ty.zigTypeTag(mod)) {19760 switch (obj_ty.zigTypeTag(mod)) {
src/type.zig+5-1
...@@ -254,7 +254,11 @@ pub const Type = struct {...@@ -254,7 +254,11 @@ pub const Type = struct {
254 .error_union_type => |error_union_type| {254 .error_union_type => |error_union_type| {
255 try print(Type.fromInterned(error_union_type.error_set_type), writer, mod);255 try print(Type.fromInterned(error_union_type.error_set_type), writer, mod);
256 try writer.writeByte('!');256 try writer.writeByte('!');
257 try print(Type.fromInterned(error_union_type.payload_type), writer, mod);257 if (error_union_type.payload_type == .generic_poison_type) {
258 try writer.writeAll("anytype");
259 } else {
260 try print(Type.fromInterned(error_union_type.payload_type), writer, mod);
261 }
258 return;262 return;
259 },263 },
260 .inferred_error_set_type => |func_index| {264 .inferred_error_set_type => |func_index| {
test/cases/compile_errors/array_init_generic_fn_with_inferred_error_set.zig created+12
...@@ -0,0 +1,12 @@
1pub export fn entry() void {
2 _ = my_func{u8} catch {};
3}
4pub export fn entry1() void {
5 _ = my_func{} catch {};
6}
7fn my_func(comptime T: type) !T {}
8
9// error
10//
11// :2:9: error: expected type 'type', found 'fn (comptime type) @typeInfo(@typeInfo(@TypeOf(tmp.my_func)).Fn.return_type.?).ErrorUnion.error_set!anytype'
12// :5:9: error: expected type 'type', found 'fn (comptime type) @typeInfo(@typeInfo(@TypeOf(tmp.my_func)).Fn.return_type.?).ErrorUnion.error_set!anytype'