FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix symbol table sub_table desync for non-simple annotation targets by youknowone · Pull Request #7300 · RustPython/RustPython · GitHub

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

Filter by extension

Filter by extension .py  (1) .rs  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 0 additions & 1 deletion Lib/test/test_type_annotations.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,6 @@ def test_non_name_annotations(self):

class RegressionTests(unittest.TestCase):
# gh-132479
@unittest.expectedFailure # TODO: RUSTPYTHON; SyntaxError: the symbol 'unique_name_6' must be present in the symbol table
def test_complex_comprehension_inlining(self):
# Test that the various repro cases from the issue don't crash
cases = [
Expand Down
22 changes: 21 additions & 1 deletion crates/codegen/src/symboltable.rs
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
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,11 @@ impl SymbolTableBuilder {
/// Annotation and TypeParams scopes act as async barriers (always non-async).
/// Comprehension scopes are transparent (inherit parent's async context).
fn is_in_async_context(&self) -> bool {
// Annotations are evaluated in a non-async scope even when
// the enclosing function is async.
if self.in_annotation {
return false;
}
for table in self.tables.iter().rev() {
match table.typ {
CompilerScope::AsyncFunction => return true,
Expand Down Expand Up @@ -1462,7 +1467,22 @@ impl SymbolTableBuilder {
self.scan_expression(target, ExpressionContext::Store)?;
}
}
self.scan_annotation(annotation)?;
// Only scan annotation in annotation scope for simple name targets.
// Non-simple annotations (subscript, attribute, parenthesized) are
// never compiled into __annotate__, so scanning them would create
// sub_tables that cause mismatch in the annotation scope's sub_table index.
let is_simple_name = *simple && matches!(&**target, Expr::Name(_));
if is_simple_name {
self.scan_annotation(annotation)?;
} else {
// Still validate annotation for forbidden expressions
// (yield, await, named) even for non-simple targets.
let was_in_annotation = self.in_annotation;
self.in_annotation = true;
let result = self.scan_expression(annotation, ExpressionContext::Load);
self.in_annotation = was_in_annotation;
result?;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if let Some(value) = value {
self.scan_expression(value, ExpressionContext::Load)?;
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL