commit 007a260cda93004c93ef1c6f2e6155cb043188b6 (tree)
parent 99adda9df5a5ae6c16b60da6ba7d57fd2154b81c
Author: Andrew Kelley <andrew@ziglang.org>
Date: Mon, 18 Feb 2019 18:12:02 -0500
Merge branch 'kristate-zig-backport-issue1944'
Diffstat:
4 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/src/analyze.cpp b/src/analyze.cpp
@@ -1634,7 +1634,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
}
} else if (param_node->data.param_decl.var_token != nullptr) {
if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
- add_node_error(g, param_node->data.param_decl.type,
+ add_node_error(g, param_node,
buf_sprintf("parameter of type 'var' not allowed in function with calling convention '%s'",
calling_convention_name(fn_type_id.cc)));
return g->builtin_types.entry_invalid;
diff --git a/std/zig/parser_test.zig b/std/zig/parser_test.zig
@@ -1,3 +1,12 @@
+test "zig fmt: infix operator and then multiline string literal" {
+ try testCanonical(
+ \\const x = "" ++
+ \\ \\ hi
+ \\;
+ \\
+ );
+}
+
test "zig fmt: C pointers" {
try testCanonical(
\\const Ptr = [*c]i32;
diff --git a/std/zig/render.zig b/std/zig/render.zig
@@ -340,7 +340,6 @@ fn renderExpression(
ast.Node.Id.InfixOp => {
const infix_op_node = @fieldParentPtr(ast.Node.InfixOp, "base", base);
- const op_token = tree.tokens.at(infix_op_node.op_token);
const op_space = switch (infix_op_node.op) {
ast.Node.InfixOp.Op.Period, ast.Node.InfixOp.Op.ErrorUnion, ast.Node.InfixOp.Op.Range => Space.None,
else => Space.Space,
@@ -353,7 +352,9 @@ fn renderExpression(
};
try renderToken(tree, stream, infix_op_node.op_token, indent, start_col, after_op_space);
- if (after_op_space == Space.Newline) {
+ if (after_op_space == Space.Newline and
+ tree.tokens.at(tree.nextToken(infix_op_node.op_token)).id != Token.Id.MultilineStringLiteralLine)
+ {
try stream.writeByteNTimes(' ', indent + indent_delta);
start_col.* = indent + indent_delta;
}
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
@@ -2,6 +2,15 @@ const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.addTest(
+ "export generic function",
+ \\export fn foo(num: var) i32 {
+ \\ return 0;
+ \\}
+ ,
+ ".tmp_source.zig:1:15: error: parameter of type 'var' not allowed in function with calling convention 'ccc'",
+ );
+
+ cases.addTest(
"C pointer to c_void",
\\export fn a() void {
\\ var x: *c_void = undefined;