Sema: fix return type of generic function is function pointer

also that's one less standalone test and one more behavior test.
This commit is contained in:
Andrew Kelley 2023-07-18 21:15:16 -07:00
parent 3145ae561d
commit c597ba32d9
5 changed files with 28 additions and 36 deletions

View File

@ -8550,8 +8550,22 @@ fn resolveGenericBody(
const err = err: {
// Make sure any nested param instructions don't clobber our work.
const prev_params = block.params;
const prev_no_partial_func_type = sema.no_partial_func_ty;
const prev_generic_owner = sema.generic_owner;
const prev_generic_call_src = sema.generic_call_src;
const prev_generic_call_decl = sema.generic_call_decl;
block.params = .{};
defer block.params = prev_params;
sema.no_partial_func_ty = true;
sema.generic_owner = .none;
sema.generic_call_src = .unneeded;
sema.generic_call_decl = .none;
defer {
block.params = prev_params;
sema.no_partial_func_ty = prev_no_partial_func_type;
sema.generic_owner = prev_generic_owner;
sema.generic_call_src = prev_generic_call_src;
sema.generic_call_decl = prev_generic_call_decl;
}
const uncasted = sema.resolveBody(block, body, func_inst) catch |err| break :err err;
const result = sema.coerce(block, dest_ty, uncasted, src) catch |err| break :err err;

View File

@ -443,3 +443,16 @@ test "generic function passed as comptime argument" {
};
try S.doMath(std.math.add, 5, 6);
}
test "return type of generic function is function pointer" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
const S = struct {
fn b(comptime T: type) ?*const fn () error{}!T {
return null;
}
};
try expect(null == S.b(void));
}

View File

@ -213,10 +213,6 @@ pub const build_cases = [_]BuildCase{
// .build_root = "test/standalone/sigpipe",
// .import = @import("standalone/sigpipe/build.zig"),
//},
.{
.build_root = "test/standalone/issue_13030",
.import = @import("standalone/issue_13030/build.zig"),
},
// TODO restore this test
//.{
// .build_root = "test/standalone/options",

View File

@ -1,24 +0,0 @@
const std = @import("std");
const builtin = @import("builtin");
const CrossTarget = std.zig.CrossTarget;
pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Test it");
b.default_step = test_step;
add(b, test_step, .Debug);
add(b, test_step, .ReleaseFast);
add(b, test_step, .ReleaseSmall);
add(b, test_step, .ReleaseSafe);
}
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
const obj = b.addObject(.{
.name = "main",
.root_source_file = .{ .path = "main.zig" },
.optimize = optimize,
.target = .{},
});
test_step.dependOn(&obj.step);
}

View File

@ -1,7 +0,0 @@
fn b(comptime T: type) ?*const fn () error{}!T {
return null;
}
export fn entry() void {
_ = b(void);
}