Merge branch 'bnoordhuis-fix795'

This commit is contained in:
Andrew Kelley 2018-02-28 00:29:20 -05:00
commit 6568be575c
2 changed files with 15 additions and 1 deletions

View File

@ -997,7 +997,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
gen_param_info->src_index = i;
gen_param_info->gen_index = SIZE_MAX;
ensure_complete_type(g, type_entry);
type_ensure_zero_bits_known(g, type_entry);
if (type_has_bits(type_entry)) {
TypeTableEntry *gen_type;
if (handle_is_ptr(type_entry)) {
@ -2129,6 +2129,7 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
if (enum_type->data.enumeration.zero_bits_loop_flag) {
enum_type->data.enumeration.zero_bits_known = true;
enum_type->data.enumeration.zero_bits_loop_flag = false;
return;
}
@ -2283,6 +2284,7 @@ static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {
// the alignment is pointer width, then assert that the first field is within that
// alignment
struct_type->data.structure.zero_bits_known = true;
struct_type->data.structure.zero_bits_loop_flag = false;
if (struct_type->data.structure.abi_alignment == 0) {
if (struct_type->data.structure.layout == ContainerLayoutPacked) {
struct_type->data.structure.abi_alignment = 1;

View File

@ -3090,4 +3090,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
,
".tmp_source.zig:11:20: error: runtime cast to union 'Value' which has non-void fields",
".tmp_source.zig:3:5: note: field 'A' has type 'i32'");
cases.add("self-referencing function pointer field",
\\const S = struct {
\\ f: fn(_: S) void,
\\};
\\fn f(_: S) void {
\\}
\\export fn entry() void {
\\ var _ = S { .f = f };
\\}
,
".tmp_source.zig:4:9: error: type 'S' is not copyable; cannot pass by value");
}