Add @Type builtin

This commit is contained in:
Jonathan Marler
2019-08-23 09:33:33 -06:00
committed by Jonathan Marler
parent 77a5f888be
commit b728cb6d4e
7 changed files with 364 additions and 0 deletions

View File

@@ -2,6 +2,58 @@ const tests = @import("tests.zig");
const builtin = @import("builtin");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"wrong type for @Type",
\\export fn entry() void {
\\ _ = @Type(0);
\\}
,
"tmp.zig:2:15: error: expected type 'builtin.TypeInfo', found 'comptime_int'",
);
cases.add(
"@Type with non-constant expression",
\\const builtin = @import("builtin");
\\var globalTypeInfo : builtin.TypeInfo = undefined;
\\export fn entry() void {
\\ _ = @Type(globalTypeInfo);
\\}
,
"tmp.zig:4:15: error: unable to evaluate constant expression",
);
cases.add(
"@Type with TypeInfo.Int",
\\const builtin = @import("builtin");
\\export fn entry() void {
\\ _ = @Type(builtin.TypeInfo.Int {
\\ .is_signed = true,
\\ .bits = 8,
\\ });
\\}
,
"tmp.zig:3:36: error: expected type 'builtin.TypeInfo', found 'builtin.Int'",
);
cases.add(
"Struct unavailable for @Type",
\\export fn entry() void {
\\ _ = @Type(@typeInfo(struct { }));
\\}
,
"tmp.zig:2:15: error: @Type not availble for 'TypeInfo.Struct'",
);
cases.add(
"array not implemented for @Type",
\\export fn entry() void {
\\ _ = @Type(@typeInfo(enum{x}));
\\}
,
"tmp.zig:2:15: error: TODO implement @Type forr 'TypeInfo.Enum': see https://github.com/ziglang/zig/issues/2907",
);
cases.add(
"wrong type for result ptr to @asyncCall",
\\export fn entry() void {