Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec: options to allow load statements in loops and conditions #554

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -2868,7 +2868,7 @@ load("module.star", "x", "y", "z") # assigns x, y, and z
load("module.star", "x", y2="y", "z") # assigns x, y2, and z
```

A load statement may not be nested inside any other statement.
A load statement may not be nested inside any other statement, unless `LoopLoads` or `ConditionalLoads` options are provided.


## Module execution
Expand Down
4 changes: 2 additions & 2 deletions resolve/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,9 @@ func (r *resolver) stmt(stmt syntax.Stmt) {
// A load statement may not be nested in any other statement.
if r.container().function != nil {
r.errorf(stmt.Load, "load statement within a function")
} else if r.loops > 0 {
} else if r.loops > 0 && !r.options.LoopLoads {
r.errorf(stmt.Load, "load statement within a loop")
} else if r.ifstmts > 0 {
} else if r.ifstmts > 0 && !r.options.ConditionalLoads {
r.errorf(stmt.Load, "load statement within a conditional")
}

Expand Down
2 changes: 2 additions & 0 deletions syntax/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type FileOptions struct {
TopLevelControl bool // allow if/for/while statements at top-level
GlobalReassign bool // allow reassignment to top-level names
LoadBindsGlobally bool // load creates global not file-local bindings (deprecated)
LoopLoads bool // allow 'load' statements within loops
ConditionalLoads bool // allow 'load' statements within conditions

// compiler
Recursion bool // disable recursion check for functions in this file
Expand Down