Commit f983adfc10
Changed files (4)
test
cases
compile_errors
src/Module.zig
@@ -1897,8 +1897,11 @@ pub const SrcLoc = struct {
const parent_node = src_loc.declRelativeToNodeIndex(node_off);
var buf: [2]Ast.Node.Index = undefined;
- const full = tree.fullArrayInit(&buf, parent_node).?;
- return tree.nodeToSpan(full.ast.type_expr);
+ const type_expr = if (tree.fullArrayInit(&buf, parent_node)) |array_init|
+ array_init.ast.type_expr
+ else
+ tree.fullStructInit(&buf, parent_node).?.ast.type_expr;
+ return tree.nodeToSpan(type_expr);
},
.node_offset_store_ptr => |node_off| {
const tree = try src_loc.file_scope.getTree(gpa);
src/Sema.zig
@@ -19753,7 +19753,8 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
const src = inst_data.src();
- const obj_ty = try sema.resolveType(block, src, inst_data.operand);
+ const ty_src: LazySrcLoc = .{ .node_offset_init_ty = inst_data.src_node };
+ const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand);
const mod = sema.mod;
switch (obj_ty.zigTypeTag(mod)) {
src/type.zig
@@ -254,7 +254,11 @@ pub const Type = struct {
.error_union_type => |error_union_type| {
try print(Type.fromInterned(error_union_type.error_set_type), writer, mod);
try writer.writeByte('!');
- try print(Type.fromInterned(error_union_type.payload_type), writer, mod);
+ if (error_union_type.payload_type == .generic_poison_type) {
+ try writer.writeAll("anytype");
+ } else {
+ try print(Type.fromInterned(error_union_type.payload_type), writer, mod);
+ }
return;
},
.inferred_error_set_type => |func_index| {
test/cases/compile_errors/array_init_generic_fn_with_inferred_error_set.zig
@@ -0,0 +1,12 @@
+pub export fn entry() void {
+ _ = my_func{u8} catch {};
+}
+pub export fn entry1() void {
+ _ = my_func{} catch {};
+}
+fn my_func(comptime T: type) !T {}
+
+// error
+//
+// :2:9: error: expected type 'type', found 'fn (comptime type) @typeInfo(@typeInfo(@TypeOf(tmp.my_func)).Fn.return_type.?).ErrorUnion.error_set!anytype'
+// :5:9: error: expected type 'type', found 'fn (comptime type) @typeInfo(@typeInfo(@TypeOf(tmp.my_func)).Fn.return_type.?).ErrorUnion.error_set!anytype'