Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,6 @@ def test_assign_call(self):
def test_assign_del(self):
self._check_error("del f()", "delete")

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_global_param_err_first(self):
source = """if 1:
def error(a):
Expand Down
34 changes: 30 additions & 4 deletions compiler/src/symboltable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,10 +1121,36 @@ impl SymbolTableBuilder {
match role {
SymbolUsage::Global => {
if !symbol.is_global() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep this if statement on the top of these errors. it will decrease hot path cost.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! I agree with that. I sent v2 code.

return Err(SymbolTableError {
error: format!("name '{}' is used prior to global declaration", name),
location,
});
if symbol.is_parameter {
return Err(SymbolTableError {
error: format!("name '{}' is parameter and global", name),
location,
});
}
if symbol.is_referenced {
return Err(SymbolTableError {
error: format!(
"name '{}' is used prior to global declaration",
name
),
location,
});
}
if symbol.is_annotated {
return Err(SymbolTableError {
error: format!("annotated name '{}' can't be global", name),
location,
});
}
if symbol.is_assigned {
return Err(SymbolTableError {
error: format!(
"name '{}' is assigned to before global declaration",
name
),
location,
});
}
}
}
SymbolUsage::Nonlocal => {
Expand Down