Add syntax error detection routine for global symbol#2903
Merged
Conversation
This commit fixes `test_global_parap_err_first` test in [test_syntax.py](https://github.com/RustPython/RustPython/blob/master/Lib/test/test_syntax.py#L678) and implement the other syntax errors detection as cpython 3.8 provided for global symbol. Below syntax error conditions are added. * name {} is parameter and global ```python >>>>> def test(a): ..... global a ..... SyntaxError: name 'a' is parameter and global at line 2 column 2 global a ``` * annotated name {} can't be global ```python >>>>> def test(): ..... a: int ..... global a ..... SyntaxError: annotated name 'a' can't be global at line 3 column 2 global a ``` * name {} is assigned to before global description ```python >>>>> a = 100 >>>>> def test(): ..... a = 10 ..... global a ..... SyntaxError: name 'a' is assigned to before global declaration at line 3 column 2 global a ``` * name {} is used prior to global declaration ```python >>>>> a = 10 >>>>> def test(): ..... print(a) ..... global a ..... SyntaxError: name 'a' is used prior to global declaration at line 3 column 2 global a ``` Signed-off-by: snowapril <sinjihng@gmail.com>
youknowone
requested changes
Aug 17, 2021
| // Role already set.. | ||
| match role { | ||
| SymbolUsage::Global => { | ||
| if !symbol.is_global() { |
Member
There was a problem hiding this comment.
let's keep this if statement on the top of these errors. it will decrease hot path cost.
Contributor
Author
There was a problem hiding this comment.
Ok! I agree with that. I sent v2 code.
add `!symbol.is_global()` condition check before entrying global symbol errors This change will decrease hot path cost. Signed-off-by: snowapril <sinjihng@gmail.com>
youknowone
approved these changes
Aug 17, 2021
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.
This revision fixes
test_global_parap_err_firsttest intest_syntax.py and implement the other syntax errors detection as cpython 3.8 provided for global symbol.
Below syntax error conditions are added.