Skip to content

Commit

Permalink
fix(syntax): Forbid use of yield/resume/resolve in global scope
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed Jan 30, 2024
1 parent 08fc824 commit 0d132fa
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5208,6 +5208,10 @@ fn asyncCall(self: *Self, _: bool) Error!Ast.Node.Index {
fn resumeFiber(self: *Self, _: bool) Error!Ast.Node.Index {
const start_location = self.current_token.? - 1;

if (self.current.?.scope_depth == 0) {
self.reportError(.syntax, "`resume` not allowed in global scope");
}

const fiber_node = try self.parsePrecedence(.Primary, false);
const node = try self.ast.appendNode(
.{
Expand Down Expand Up @@ -5262,6 +5266,10 @@ fn resumeFiber(self: *Self, _: bool) Error!Ast.Node.Index {
fn resolveFiber(self: *Self, _: bool) Error!Ast.Node.Index {
const start_location = self.current_token.? - 1;

if (self.current.?.scope_depth == 0) {
self.reportError(.syntax, "`resolve` not allowed in global scope");
}

const fiber = try self.parsePrecedence(.Primary, false);
const node = try self.ast.appendNode(
.{
Expand Down Expand Up @@ -5313,6 +5321,11 @@ fn resolveFiber(self: *Self, _: bool) Error!Ast.Node.Index {

fn yield(self: *Self, _: bool) Error!Ast.Node.Index {
const start_location = self.current_token.? - 1;

if (self.current.?.scope_depth == 0) {
self.reportError(.syntax, "`yield` not allowed in global scope");
}

const expr = try self.parsePrecedence(.Primary, false);

return try self.ast.appendNode(
Expand Down

0 comments on commit 0d132fa

Please sign in to comment.