update compile error tests and some doc comments

This commit is contained in:
Vexu 2020-07-11 22:04:38 +03:00
parent 3e095d8ef3
commit be1507a7af
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
8 changed files with 56 additions and 51 deletions

View File

@ -212,7 +212,7 @@ const Tokenizer = struct {
}
};
fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, args: var) anyerror {
fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, args: anytype) anyerror {
const loc = tokenizer.getTokenLocation(token);
const args_prefix = .{ tokenizer.source_file_name, loc.line + 1, loc.column + 1 };
warn("{}:{}:{}: error: " ++ fmt ++ "\n", args_prefix ++ args);
@ -634,7 +634,7 @@ fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 {
return buf.toOwnedSlice();
}
fn writeEscaped(out: var, input: []const u8) !void {
fn writeEscaped(out: anytype, input: []const u8) !void {
for (input) |c| {
try switch (c) {
'&' => out.writeAll("&"),
@ -765,7 +765,7 @@ fn isType(name: []const u8) bool {
return false;
}
fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Token, raw_src: []const u8) !void {
fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token: Token, raw_src: []const u8) !void {
const src = mem.trim(u8, raw_src, " \n");
try out.writeAll("<code class=\"zig\">");
var tokenizer = std.zig.Tokenizer.init(src);
@ -825,6 +825,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
.Keyword_volatile,
.Keyword_allowzero,
.Keyword_while,
.Keyword_anytype,
=> {
try out.writeAll("<span class=\"tok-kw\">");
try writeEscaped(out, src[token.loc.start..token.loc.end]);
@ -977,12 +978,12 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
try out.writeAll("</code>");
}
fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: var, source_token: Token) !void {
fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: anytype, source_token: Token) !void {
const raw_src = docgen_tokenizer.buffer[source_token.start..source_token.end];
return tokenizeAndPrintRaw(docgen_tokenizer, out, source_token, raw_src);
}
fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var, zig_exe: []const u8) !void {
fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: anytype, zig_exe: []const u8) !void {
var code_progress_index: usize = 0;
var env_map = try process.getEnvMap(allocator);

View File

@ -69,7 +69,7 @@ fn peekIsAlign(comptime fmt: []const u8) bool {
///
/// If a formatted user type contains a function of the type
/// ```
/// pub fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: var) !void
/// pub fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void
/// ```
/// with `?` being the type formatted, this function will be called instead of the default implementation.
/// This allows user types to be formatted in a logical manner instead of dumping all fields of the type.

View File

@ -16,14 +16,16 @@ pub const Packing = enum {
};
/// Creates a deserializer that deserializes types from any stream.
/// If `is_packed` is true, the data stream is treated as bit-packed,
/// otherwise data is expected to be packed to the smallest byte.
/// Types may implement a custom deserialization routine with a
/// function named `deserialize` in the form of:
/// pub fn deserialize(self: *Self, deserializer: var) !void
/// which will be called when the deserializer is used to deserialize
/// that type. It will pass a pointer to the type instance to deserialize
/// into and a pointer to the deserializer struct.
/// If `is_packed` is true, the data stream is treated as bit-packed,
/// otherwise data is expected to be packed to the smallest byte.
/// Types may implement a custom deserialization routine with a
/// function named `deserialize` in the form of:
/// ```
/// pub fn deserialize(self: *Self, deserializer: anytype) !void
/// ```
/// which will be called when the deserializer is used to deserialize
/// that type. It will pass a pointer to the type instance to deserialize
/// into and a pointer to the deserializer struct.
pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, comptime ReaderType: type) type {
return struct {
in_stream: if (packing == .Bit) io.BitReader(endian, ReaderType) else ReaderType,
@ -108,7 +110,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
const C = comptime meta.Child(T);
const child_type_id = @typeInfo(C);
//custom deserializer: fn(self: *Self, deserializer: var) !void
//custom deserializer: fn(self: *Self, deserializer: anytype) !void
if (comptime trait.hasFn("deserialize")(C)) return C.deserialize(ptr, self);
if (comptime trait.isPacked(C) and packing != .Bit) {
@ -196,18 +198,20 @@ pub fn deserializer(
}
/// Creates a serializer that serializes types to any stream.
/// If `is_packed` is true, the data will be bit-packed into the stream.
/// Note that the you must call `serializer.flush()` when you are done
/// writing bit-packed data in order ensure any unwritten bits are committed.
/// If `is_packed` is false, data is packed to the smallest byte. In the case
/// of packed structs, the struct will written bit-packed and with the specified
/// endianess, after which data will resume being written at the next byte boundary.
/// Types may implement a custom serialization routine with a
/// function named `serialize` in the form of:
/// pub fn serialize(self: Self, serializer: var) !void
/// which will be called when the serializer is used to serialize that type. It will
/// pass a const pointer to the type instance to be serialized and a pointer
/// to the serializer struct.
/// If `is_packed` is true, the data will be bit-packed into the stream.
/// Note that the you must call `serializer.flush()` when you are done
/// writing bit-packed data in order ensure any unwritten bits are committed.
/// If `is_packed` is false, data is packed to the smallest byte. In the case
/// of packed structs, the struct will written bit-packed and with the specified
/// endianess, after which data will resume being written at the next byte boundary.
/// Types may implement a custom serialization routine with a
/// function named `serialize` in the form of:
/// ```
/// pub fn serialize(self: Self, serializer: anytype) !void
/// ```
/// which will be called when the serializer is used to serialize that type. It will
/// pass a const pointer to the type instance to be serialized and a pointer
/// to the serializer struct.
pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, comptime OutStreamType: type) type {
return struct {
out_stream: if (packing == .Bit) io.BitOutStream(endian, OutStreamType) else OutStreamType,
@ -270,7 +274,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
return;
}
//custom serializer: fn(self: Self, serializer: var) !void
//custom serializer: fn(self: Self, serializer: anytype) !void
if (comptime trait.hasFn("serialize")(T)) return T.serialize(value, self);
if (comptime trait.isPacked(T) and packing != .Bit) {

View File

@ -22,7 +22,7 @@ const root = @import("root");
//! comptime level: std.log.Level,
//! comptime scope: @TypeOf(.EnumLiteral),
//! comptime format: []const u8,
//! args: var,
//! args: anytype,
//! ) void {
//! // Ignore all non-critical logging from sources other than
//! // .my_project and .nice_library

View File

@ -1052,12 +1052,12 @@ pub const Node = struct {
const params_len: usize = if (self.params_len == 0)
0
else switch (self.paramsConst()[self.params_len - 1].param_type) {
.var_type, .type_expr => self.params_len,
.any_type, .type_expr => self.params_len,
.var_args => self.params_len - 1,
};
if (i < params_len) {
switch (self.paramsConst()[i].param_type) {
.var_type => |n| return n,
.any_type => |n| return n,
.var_args => unreachable,
.type_expr => |n| return n,
}

View File

@ -1132,7 +1132,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool {
const param_types = try fn_type_scope.arena.alloc(*zir.Inst, param_decls.len);
for (param_decls) |param_decl, i| {
const param_type_node = switch (param_decl.param_type) {
.var_type => |node| return self.failNode(&fn_type_scope.base, node, "TODO implement anytype parameter", .{}),
.any_type => |node| return self.failNode(&fn_type_scope.base, node, "TODO implement anytype parameter", .{}),
.var_args => |tok| return self.failTok(&fn_type_scope.base, tok, "TODO implement var args", .{}),
.type_expr => |node| node,
};

View File

@ -1511,13 +1511,13 @@ ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
}
for (; i < fn_type_id->param_count; i += 1) {
const char *comma_str = (i == 0) ? "" : ",";
buf_appendf(&fn_type->name, "%svar", comma_str);
buf_appendf(&fn_type->name, "%sanytype", comma_str);
}
buf_append_str(&fn_type->name, ")");
if (fn_type_id->cc != CallingConventionUnspecified) {
buf_appendf(&fn_type->name, " callconv(.%s)", calling_convention_name(fn_type_id->cc));
}
buf_append_str(&fn_type->name, " var");
buf_append_str(&fn_type->name, " anytype");
fn_type->data.fn.fn_type_id = *fn_type_id;
fn_type->data.fn.is_generic = true;

View File

@ -42,7 +42,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\fn foo() Foo {
\\ return .{ .x = 42 };
\\}
\\fn bar(val: var) Foo {
\\fn bar(val: anytype) Foo {
\\ return .{ .x = val };
\\}
\\export fn entry() void {
@ -1034,7 +1034,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ storev(&v[i], 42);
\\}
\\
\\fn storev(ptr: var, val: i32) void {
\\fn storev(ptr: anytype, val: i32) void {
\\ ptr.* = val;
\\}
, &[_][]const u8{
@ -1049,7 +1049,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ var x = loadv(&v[i]);
\\}
\\
\\fn loadv(ptr: var) i32 {
\\fn loadv(ptr: anytype) i32 {
\\ return ptr.*;
\\}
, &[_][]const u8{
@ -1832,7 +1832,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ while (true) {}
\\}
, &[_][]const u8{
"error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,var) var'",
"error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,anytype) anytype'",
"note: only one of the functions is generic",
});
@ -2032,11 +2032,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("export generic function",
\\export fn foo(num: var) i32 {
\\export fn foo(num: anytype) i32 {
\\ return 0;
\\}
, &[_][]const u8{
"tmp.zig:1:15: error: parameter of type 'var' not allowed in function with calling convention 'C'",
"tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C'",
});
cases.add("C pointer to c_void",
@ -2836,7 +2836,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("missing parameter name of generic function",
\\fn dump(var) void {}
\\fn dump(anytype) void {}
\\export fn entry() void {
\\ var a: u8 = 9;
\\ dump(a);
@ -2859,13 +2859,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("generic fn as parameter without comptime keyword",
\\fn f(_: fn (var) void) void {}
\\fn g(_: var) void {}
\\fn f(_: fn (anytype) void) void {}
\\fn g(_: anytype) void {}
\\export fn entry() void {
\\ f(g);
\\}
, &[_][]const u8{
"tmp.zig:1:9: error: parameter of type 'fn(var) var' must be declared comptime",
"tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime",
});
cases.add("optional pointer to void in extern struct",
@ -3165,7 +3165,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add("var makes structs required to be comptime known",
\\export fn entry() void {
\\ const S = struct{v: var};
\\ const S = struct{v: anytype};
\\ var s = S{.v=@as(i32, 10)};
\\}
, &[_][]const u8{
@ -6072,10 +6072,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("calling a generic function only known at runtime",
\\var foos = [_]fn(var) void { foo1, foo2 };
\\var foos = [_]fn(anytype) void { foo1, foo2 };
\\
\\fn foo1(arg: var) void {}
\\fn foo2(arg: var) void {}
\\fn foo1(arg: anytype) void {}
\\fn foo2(arg: anytype) void {}
\\
\\pub fn main() !void {
\\ foos[0](true);
@ -6920,12 +6920,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("getting return type of generic function",
\\fn generic(a: var) void {}
\\fn generic(a: anytype) void {}
\\comptime {
\\ _ = @TypeOf(generic).ReturnType;
\\}
, &[_][]const u8{
"tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var) var' is generic",
"tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(anytype) anytype' is generic",
});
cases.add("unsupported modifier at start of asm output constraint",
@ -7493,7 +7493,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("issue #5221: invalid struct init type referenced by @typeInfo and passed into function",
\\fn ignore(comptime param: var) void {}
\\fn ignore(comptime param: anytype) void {}
\\
\\export fn foo() void {
\\ const MyStruct = struct {