fix crash on multiline library name

This commit is contained in:
Vexu 2020-01-14 16:39:54 +02:00 committed by Andrew Kelley
parent 50754ba336
commit af2ede4d96
2 changed files with 16 additions and 1 deletions

View File

@ -285,7 +285,12 @@ fn parseTopLevelDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
if (extern_export_inline_token) |token| {
if (lib_name) |string_literal_node|
putBackToken(it, string_literal_node.cast(Node.StringLiteral).?.token);
if (string_literal_node.cast(Node.StringLiteral)) |single| {
putBackToken(it, single.token);
} else if (string_literal_node.cast(Node.MultilineStringLiteral)) |multi| {
while (multi.lines.pop()) |line|
putBackToken(it, line);
} else unreachable;
putBackToken(it, token);
return null;
}

View File

@ -2721,6 +2721,16 @@ test "zig fmt: extern without container keyword returns error" {
);
}
test "zig fmt: extern multiline lib name" {
try testError(
\\extern \\super
\\ \\long
\\ \\library
\\ \\name
\\
);
}
const std = @import("std");
const mem = std.mem;
const warn = std.debug.warn;