mirror of
https://github.com/ziglang/zig.git
synced 2026-01-31 03:33:37 +00:00
commit
d09d61be97
@ -2976,7 +2976,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
|
||||
|
||||
// Even though we reuse the constant instruction, we still remove it from the
|
||||
// block so that codegen does not see it.
|
||||
block.instructions.shrinkRetainingCapacity(block.instructions.items.len - 3);
|
||||
block.instructions.shrinkRetainingCapacity(search_index);
|
||||
sema.air_values.items[value_index] = try Value.Tag.decl_ref.create(sema.arena, new_decl_index);
|
||||
// if bitcast ty ref needs to be made const, make_ptr_const
|
||||
// ZIR handles it later, so we can just use the ty ref here.
|
||||
@ -13011,10 +13011,13 @@ fn analyzeRet(
|
||||
const backend_supports_error_return_tracing =
|
||||
sema.mod.comp.bin_file.options.use_llvm;
|
||||
|
||||
if ((sema.fn_ret_ty.zigTypeTag() == .ErrorSet or sema.typeOf(uncasted_operand).zigTypeTag() == .ErrorUnion) and
|
||||
if (sema.fn_ret_ty.isError() and
|
||||
sema.mod.comp.bin_file.options.error_return_tracing and
|
||||
backend_supports_error_return_tracing)
|
||||
{
|
||||
ret_err: {
|
||||
if (try sema.resolveMaybeUndefVal(block, src, operand)) |ret_val| {
|
||||
if (ret_val.tag() != .@"error") break :ret_err;
|
||||
}
|
||||
const return_err_fn = try sema.getBuiltin(block, src, "returnError");
|
||||
const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace");
|
||||
const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty);
|
||||
|
||||
24
src/type.zig
24
src/type.zig
@ -640,18 +640,18 @@ pub const Type = extern union {
|
||||
if (!eql(a_info.return_type, b_info.return_type, mod))
|
||||
return false;
|
||||
|
||||
if (a_info.cc != b_info.cc)
|
||||
return false;
|
||||
|
||||
if (a_info.alignment != b_info.alignment)
|
||||
return false;
|
||||
|
||||
if (a_info.is_var_args != b_info.is_var_args)
|
||||
return false;
|
||||
|
||||
if (a_info.is_generic != b_info.is_generic)
|
||||
return false;
|
||||
|
||||
if (!a_info.cc_is_generic and a_info.cc != b_info.cc)
|
||||
return false;
|
||||
|
||||
if (!a_info.align_is_generic and a_info.alignment != b_info.alignment)
|
||||
return false;
|
||||
|
||||
if (a_info.param_types.len != b_info.param_types.len)
|
||||
return false;
|
||||
|
||||
@ -1036,9 +1036,15 @@ pub const Type = extern union {
|
||||
std.hash.autoHash(hasher, std.builtin.TypeId.Fn);
|
||||
|
||||
const fn_info = ty.fnInfo();
|
||||
hashWithHasher(fn_info.return_type, hasher, mod);
|
||||
std.hash.autoHash(hasher, fn_info.alignment);
|
||||
std.hash.autoHash(hasher, fn_info.cc);
|
||||
if (fn_info.return_type.tag() != .generic_poison) {
|
||||
hashWithHasher(fn_info.return_type, hasher, mod);
|
||||
}
|
||||
if (!fn_info.align_is_generic) {
|
||||
std.hash.autoHash(hasher, fn_info.alignment);
|
||||
}
|
||||
if (!fn_info.cc_is_generic) {
|
||||
std.hash.autoHash(hasher, fn_info.cc);
|
||||
}
|
||||
std.hash.autoHash(hasher, fn_info.is_var_args);
|
||||
std.hash.autoHash(hasher, fn_info.is_generic);
|
||||
|
||||
|
||||
@ -977,3 +977,31 @@ test "weird array and tuple initializations" {
|
||||
.b = if (a) .{ .e = .a } else .{ .e = .b },
|
||||
};
|
||||
}
|
||||
|
||||
test "array type comes from generic function" {
|
||||
const S = struct {
|
||||
fn A() type {
|
||||
return struct { a: u8 = 0 };
|
||||
}
|
||||
};
|
||||
const args = [_]S.A(){.{}};
|
||||
_ = args;
|
||||
}
|
||||
|
||||
test "generic function uses return type of other generic function" {
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
|
||||
const S = struct {
|
||||
fn call(
|
||||
f: anytype,
|
||||
args: anytype,
|
||||
) @TypeOf(@call(.{}, f, @as(@TypeOf(args), undefined))) {
|
||||
return @call(.{}, f, args);
|
||||
}
|
||||
|
||||
fn func(arg: anytype) @TypeOf(arg) {
|
||||
return arg;
|
||||
}
|
||||
};
|
||||
try std.testing.expect(S.call(S.func, .{@as(u8, 1)}) == 1);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user