-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Optionally allow redefinition of variable with different type #6197
Merged
Merged
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
8e49664
Support redefinition of local variables with a different type
JukkaL 3b409fc
Add docstring
JukkaL 71cb8ea
Allow redefinitions of form "x = f(x)"
JukkaL 35f56ae
Fix special cases
JukkaL 2524777
Add test cases
JukkaL ab70d0d
Fix redefinition with 'break' and 'continue'
JukkaL 525d5f4
Fix issues
JukkaL 2c614a2
Fix some edge cases
JukkaL bf2f869
Support top-level redefinition through renaming (WIP)
JukkaL 9e2c6b8
Remove obsolete code
JukkaL 2b885da
Cleanup
JukkaL 712669c
Merge transform code into a single class
JukkaL e0b7df0
Code cleanup
JukkaL f153809
Fix issues
JukkaL 856d401
Fix issues
JukkaL 865f1dd
Work around type check error
JukkaL 2deff14
Merge branch 'master' into redefine-var
JukkaL 27a1e57
Fix merge issue
JukkaL f04e37a
Fix lint
JukkaL 1f9f62e
Fix more tests
JukkaL 9ba82a9
Rename semanal_redef -> renaming
JukkaL fbf052e
Only perform redefinition if variable has been read
JukkaL 1116b47
A few fixes
JukkaL 70a3085
Add hacky workaround for 'self'
JukkaL cfad560
Merge branch 'master' into redefine-var
JukkaL b57960b
Remove unused things
JukkaL 580a774
Revert some unnecessary changes
JukkaL 051e695
Merge commit '3bea26f89a66834f42caaa90cf8db44f99d39dcc' into redefine…
JukkaL 77495fb
Merge branch 'master' into redefine-var
JukkaL dc03143
Fix test case
JukkaL 4ceed87
Merge branch 'master' into redefine-var
JukkaL ac00e6d
Merge branch 'master' into redefine-var
JukkaL 20fd0f9
Use `if int():` consistently
JukkaL 3843cea
Fix some test cases
JukkaL 5cfaf9c
Add flag for allowing redefinitions
JukkaL 83ba85f
Use the flag
JukkaL 43a0362
Fix tests
JukkaL 59b3413
Fix test cases
JukkaL 7e3eff9
Add test case for turning flag off explicitly
JukkaL afa1096
Rename flag to --[dis]allow-redefinition (no plural)
JukkaL 916288c
Fix semantic analyzer tests
JukkaL 459187e
Update test case
JukkaL e165e46
Merge branch 'master' into redefine-var
JukkaL 0a119b3
Merge branch 'master' into redefine-var
JukkaL fadb322
Merge branch 'master' into redefine-var
JukkaL 76ad071
Fix brokenness from merge
JukkaL 979a17c
Respond to review
JukkaL ae0043f
Clarify code
JukkaL 512c1ed
Test additional special case
JukkaL 1f7e36d
Add test case
JukkaL 72043ae
Fix with statements
JukkaL 8c30c90
Remove unnecessary check
JukkaL e390f38
Add comment
JukkaL bc0ee19
Ensure renaming cannot happen across scopes in class
JukkaL 54b86d8
Remove unnecessary call
JukkaL 496d2dd
The final assignments takes precedence in class when renaming
JukkaL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
A few fixes
- Loading branch information
commit 1116b477ee1030af9981e1251fd437db53bb6a78
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,7 +165,7 @@ def analyze_lvalue(self, lvalue: Lvalue, is_nested: bool = False) -> None: | |
lvalue.base.accept(self) | ||
lvalue.index.accept(self) | ||
elif isinstance(lvalue, StarExpr): | ||
self.analyze_lvalue(lvalue.expr) | ||
self.analyze_lvalue(lvalue.expr, is_nested=is_nested) | ||
|
||
def visit_name_expr(self, expr: NameExpr) -> None: | ||
self.handle_ref(expr) | ||
|
@@ -176,6 +176,7 @@ def handle_arg(self, name: str) -> None: | |
"""Store function argument.""" | ||
if name not in self.refs[-1]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I am missing something, but why do we need this check? Shouldn't all function arguments have unique names? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the check. |
||
self.refs[-1][name] = [[]] | ||
self.num_reads[-1][name] = 0 | ||
|
||
def handle_def(self, expr: NameExpr) -> None: | ||
"""Store new name definition.""" | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explain that we pass
is_nested=is_nested
because a typical use case isx, y, *rest = stuff
(rest
may be reused).