aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVexu <git@vexu.eu>2020-05-16 20:49:37 +0300
committerGitHub <noreply@github.com>2020-05-16 20:49:37 +0300
commiteda03354dc865fc18b8bc5862eb837fd8a6e979c (patch)
treeded5dc0cd2b1badf10b1904333d6a30e418874c1 /lib
parentcf34480f2a3a1e52c09fe762dad34c45d5485717 (diff)
parent081ffe24cf99db6544293aecfbd6834a0daf6680 (diff)
downloadzig-eda03354dc865fc18b8bc5862eb837fd8a6e979c.tar.gz
zig-eda03354dc865fc18b8bc5862eb837fd8a6e979c.zip
Merge pull request #5358 from Vexu/parser
Fix infinite loop with invalid comptime
Diffstat (limited to 'lib')
-rw-r--r--lib/std/zig/ast.zig4
-rw-r--r--lib/std/zig/parse.zig6
-rw-r--r--lib/std/zig/parser_test.zig8
3 files changed, 18 insertions, 0 deletions
diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig
index 0a0a822603..fcbb090ace 100644
--- a/lib/std/zig/ast.zig
+++ b/lib/std/zig/ast.zig
@@ -165,6 +165,7 @@ pub const Error = union(enum) {
ExpectedLoopExpr: ExpectedLoopExpr,
ExpectedDerefOrUnwrap: ExpectedDerefOrUnwrap,
ExpectedSuffixOp: ExpectedSuffixOp,
+ ExpectedBlockOrField: ExpectedBlockOrField,
DeclBetweenFields: DeclBetweenFields,
InvalidAnd: InvalidAnd,
@@ -215,6 +216,7 @@ pub const Error = union(enum) {
.ExpectedLoopExpr => |*x| return x.render(tokens, stream),
.ExpectedDerefOrUnwrap => |*x| return x.render(tokens, stream),
.ExpectedSuffixOp => |*x| return x.render(tokens, stream),
+ .ExpectedBlockOrField => |*x| return x.render(tokens, stream),
.DeclBetweenFields => |*x| return x.render(tokens, stream),
.InvalidAnd => |*x| return x.render(tokens, stream),
}
@@ -267,6 +269,7 @@ pub const Error = union(enum) {
.ExpectedLoopExpr => |x| return x.token,
.ExpectedDerefOrUnwrap => |x| return x.token,
.ExpectedSuffixOp => |x| return x.token,
+ .ExpectedBlockOrField => |x| return x.token,
.DeclBetweenFields => |x| return x.token,
.InvalidAnd => |x| return x.token,
}
@@ -306,6 +309,7 @@ pub const Error = union(enum) {
pub const ExpectedLoopExpr = SingleTokenError("Expected loop expression, found '{}'");
pub const ExpectedDerefOrUnwrap = SingleTokenError("Expected pointer dereference or optional unwrap, found '{}'");
pub const ExpectedSuffixOp = SingleTokenError("Expected pointer dereference, optional unwrap, or field access, found '{}'");
+ pub const ExpectedBlockOrField = SingleTokenError("Expected block or field, found '{}'");
pub const ExpectedParamType = SimpleError("Expected parameter type");
pub const ExpectedPubItem = SimpleError("Expected function or variable declaration after pub");
diff --git a/lib/std/zig/parse.zig b/lib/std/zig/parse.zig
index d3b970513e..001799e0b1 100644
--- a/lib/std/zig/parse.zig
+++ b/lib/std/zig/parse.zig
@@ -231,6 +231,12 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree, top
const next = it.peek().?.id;
switch (next) {
.Eof => break,
+ .Keyword_comptime => {
+ _ = nextToken(it);
+ try tree.errors.push(.{
+ .ExpectedBlockOrField = .{ .token = it.index },
+ });
+ },
else => {
const index = it.index;
if (next == .RBrace) {
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig
index 992abc57c7..ef8779e7f6 100644
--- a/lib/std/zig/parser_test.zig
+++ b/lib/std/zig/parser_test.zig
@@ -200,6 +200,14 @@ test "recovery: missing semicolon after if, for, while stmt" {
});
}
+test "recovery: invalid comptime" {
+ try testError(
+ \\comptime
+ , &[_]Error{
+ .ExpectedBlockOrField,
+ });
+}
+
test "zig fmt: top-level fields" {
try testCanonical(
\\a: did_you_know,