fixed IfTypeExpr parsing

This commit is contained in:
Vexu 2019-06-24 10:29:58 +03:00 committed by Andrew Kelley
parent e79e8993e6
commit fa42c99d82
2 changed files with 14 additions and 2 deletions

View File

@ -2833,8 +2833,8 @@ fn parseIf(arena: *Allocator, it: *TokenIterator, tree: *Tree, bodyParseFn: Node
const else_token = eatToken(it, .Keyword_else) orelse return node;
const payload = try parsePayload(arena, it, tree);
const else_expr = try expectNode(arena, it, tree, parseExpr, AstError{
.ExpectedExpr = AstError.ExpectedExpr{ .token = it.index },
const else_expr = try expectNode(arena, it, tree, bodyParseFn, AstError{
.InvalidToken = AstError.InvalidToken{ .token = it.index },
});
const else_node = try arena.create(Node.Else);
else_node.* = Node.Else{

View File

@ -2234,6 +2234,18 @@ test "zig fmt: multiline string in array" {
);
}
test "zig fmt: if type expr" {
try testCanonical(
\\const mycond = true;
\\pub fn foo() if (mycond) i32 else void {
\\ if (mycond) {
\\ return 42;
\\ }
\\}
\\
);
}
const std = @import("std");
const mem = std.mem;
const warn = std.debug.warn;