resolve: allow if/for/while statements at toplevel#103
resolve: allow if/for/while statements at toplevel#103alandonovan wants to merge 1 commit intomasterfrom
Conversation
These constructs are still disallowed in the Bazel build language, but it is easy to check for them as a separate pass over the syntax tree, so there is no need to complicate the spec with this restriction, which is a nuisance in other dialects. Clients that set the -globalreassign flag to suppress the check need do so no longer. Change-Id: I39ddb2128e6151a878a884fdb84d7017df2d5d51
02f3b29 to
45e0e2b
Compare
jayconrod
left a comment
There was a problem hiding this comment.
The code here seems sound, but I'm not sure I understand the premise. if and for are still forbidden at top-level in the canonical Starlark spec. It's part of the language, right, not Bazel's validation? It seems like this should still be behind a dialect flag.
|
Correct. I am suggesting that the Starlark spec should say the same thing, and we specify the restrictions in to the Bazel manual. Ping @laurentlb |
Bazel already needs to inspect the AST for other reasons, for example, it disallows f(**kwargs) in a BUILD file. So it already has a place to do this check, and it already has (I assume) a place in its manual to explain the notion of syntax restrictions. |
|
Can you have it behind a flag for now? |
Have what behind a flag, exactly? A Bazel-like tool using Starlark-go already must inspect the syntax tree to reject def and f(**kwargs) in BUILD files, so it is trivial for it to also check for toplevel if/for/while at that point by adding these 8 lines of code: No other client besides Bazel seems to need or want this behavior. |
|
As it doesn't follow the specification, I think it's preferable to have a flag to allow if/for at top-level. Users should explicitly opt in if they prefer this behavior.
|
Laurent, we own the specification and it is wrong. Let's change it. |
Isn't that supported already? Is this PR stale? |
|
This PR is really a request to change the spec to match reality: top-level if/for are permitted in all dialects except for Bazel, which imposes various unique restrictions on BUILD and .bzl files, this being one of them. |
These constructs are still disallowed in the Bazel build language,
but it is easy to check for them as a separate pass over the syntax tree,
so there is no need to complicate the spec with this restriction,
which is a nuisance in other dialects.
Clients that set the -globalreassign flag to suppress the check
need do so no longer.