Merge branch 'kristate-zig-backport-issue1944'

This commit is contained in:
Andrew Kelley 2019-02-18 18:12:02 -05:00
commit 007a260cda
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
4 changed files with 22 additions and 3 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -1,6 +1,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 {