Add cast and isinstance keywords - #1505
Merged
Merged
Conversation
Member
|
Needs a rebase after the Buck2 fix |
fmeum
approved these changes
Sep 4, 2026
Member
|
I unfortunately missed that this didn't end up merging for v10. I will send a v10.0.2 with this and argue for it to be a bugfix for type support, but call out the incompatible change. |
Finishing support for the type syntax proposed in bazelbuild/starlark#362 After some reflection, I think we should always parse cast/isinstance as keywords (requiring 2 arguments, one of which is a value expression and the other a type expression) since permitting pre-type Starlark syntax is likely to only lead to confusion, and would be quite difficult to get right. Note that we observe no occurrences of `cast` or `isinstance` as identifiers in any Starlark code in the Google's monorepo. Store the parsed cast/isinstance exprs as CallExpr-s (to avoid diverging their formatting/walking/etc. support from call expressions) with an enum field to mark that they are of a special kind.
fmeum
force-pushed
the
cast-isinstance
branch
from
September 16, 2026 10:48
31ec922 to
287fa81
Compare
fmeum
approved these changes
Sep 16, 2026
fmeum
enabled auto-merge (squash)
September 16, 2026 10:49
Member
|
@tetromino I rebased the PR onto main and will merge it now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Finishing support for the type syntax proposed in bazelbuild/starlark#362
After some reflection, I think we should always parse cast/isinstance as keywords (requiring 2 arguments, one of which is a value expression and the other a type expression) since permitting pre-type Starlark syntax is likely to only lead to confusion, and would be quite difficult to get right.
Note that this is an incompatible change: forms like
cast(x, y, z)orcast = foowill now be a parse error. However, in practice, I observe no occurrences ofcastorisinstanceused as identifiers in any Starlark code in Google's monorepo, so I believe that it's rather unlikely to break anyone.Store the parsed cast/isinstance exprs as
CallExpr-s (to avoid diverging their formatting/walking/etc. support from call expressions) with an enum field to mark that they are of a special kind.Buildtools PR checklist