-
-
Notifications
You must be signed in to change notification settings - Fork 393
Local Variable Type Hints #7892
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
Draft
APickledWalrus
wants to merge
18
commits into
dev/feature
Choose a base branch
from
feature/local-variable-type-hints
base: dev/feature
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
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
These syntaxes were giving some false positive warnings
We do not want to copy hints from sections containing a statement that terminate the trigger
Draft
sovdeeth
requested changes
May 30, 2025
Variables will always use converters. so this allows us to represent a broader range of types (and likely reduce mistakes)
This was
linked to
issues
Jun 4, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
An issue that needs to be fixed. Alternatively, a PR fixing an issue.
feature
Pull request adding a new feature.
needs testing
Needs testing to determine current status or issue validity, or for WIP feature pulls.
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.
Problem
Local variables are essentially accepted wherever they are used. This results in more potential mistakes and (some) strange syntax behavior that is hard to track. Detailed type information for variables helps in two cases:
1. Mismatched types
It's possible you use the wrong variable somewhere. Detailed type information can catch this and print a warning (or error). Consider:
We can catch that
{_a} in lowercase
is likely to be invalid and alert the user.2. Syntax accepting objects
Consider syntax like ExprArithmetic:
With detailed type information, we can now identify at parse time that this is an invalid operation, instead of failing at runtime and returning none.
Solution
With systems like ExecutionIntent and multiple return types, we are finally in a position to execute this system well. Type tracking for local variables has been implemented across syntax interacting with variables using a HintManager that is attached to the ParserInstance.
The testing script along with HintManager's documentation provide insight into how hints are managed.
Assuming I can get this stable enough (i.e., depend on the type hints and avoid Object), I would likely consider making this an error. Due to addons, we might need a way to escape the error (operating "unsafely"?).
While the current draft is (somewhat) stable, further testing is needed, especially with addons.
Testing Completed
I have added a basic
type hints.sk
test (more to come). I plan to implement JUnit testing for HintManager.Supporting Information
Depends on:
Completes:
Related: