@sizeOf returns 0 for comptime types

This defines `@sizeOf` to be the runtime size of a type, which means
that it is zero for types such as comptime_int, type, and (enum
literal).

See #2209
This commit is contained in:
Andrew Kelley
2019-04-24 22:31:53 -04:00
parent 733c547a65
commit fb2acaff06
4 changed files with 25 additions and 5 deletions

View File

@@ -2,6 +2,15 @@ const tests = @import("tests.zig");
const builtin = @import("builtin");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"@sizeOf bad type",
\\export fn entry() void {
\\ _ = @sizeOf(@typeOf(null));
\\}
,
"tmp.zig:2:17: error: no size available for type '(null)'",
);
cases.add(
"Generic function where return type is self-referenced",
\\fn Foo(comptime T: type) Foo(T) {