zig/test/behavior/bugs/2006.zig
Andrew Kelley cc937369fb stage2: Type.hasCodeGenBits asserts structs and unions have fields
Previously, this function would return an incorrect result for structs
and unions which did not have their fields resolved yet.

This required introducing more logic in Sema to resolve types before
doing certain things such as creating an anonmyous Decl and emitting
function call AIR.

As a result a couple more struct tests pass.

Oh, and I implemented the language change to make sizeOf for pointers
always return pointer size bytes even if the element type is 0 bits.
2021-12-22 20:29:26 -07:00

20 lines
564 B
Zig

const std = @import("std");
const expect = std.testing.expect;
const S = struct {
p: *S,
};
test "bug 2006" {
var a: S = undefined;
a = S{ .p = undefined };
try expect(@sizeOf(S) != 0);
if (@import("builtin").zig_is_stage2) {
// It is an accepted proposal to make `@sizeOf` for pointers independent
// of whether the element type is zero bits.
// This language change has not been implemented in stage1.
try expect(@sizeOf(*void) == @sizeOf(*i32));
} else {
try expect(@sizeOf(*void) == 0);
}
}