Skip to content

Commit 8b61e74

Browse files
committed
Validate forbidden expressions in non-simple annotation targets
Fix cspell "desynchronize" warning and validate yield/await/named/async comprehension expressions in non-simple annotations without creating annotation scopes.
1 parent 3ecdd0c commit 8b61e74

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

crates/codegen/src/symboltable.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,11 @@ impl SymbolTableBuilder {
10531053
/// Annotation and TypeParams scopes act as async barriers (always non-async).
10541054
/// Comprehension scopes are transparent (inherit parent's async context).
10551055
fn is_in_async_context(&self) -> bool {
1056+
// Annotations are evaluated in a non-async scope even when
1057+
// the enclosing function is async.
1058+
if self.in_annotation {
1059+
return false;
1060+
}
10561061
for table in self.tables.iter().rev() {
10571062
match table.typ {
10581063
CompilerScope::AsyncFunction => return true,
@@ -1465,10 +1470,17 @@ impl SymbolTableBuilder {
14651470
// Only scan annotation in annotation scope for simple name targets.
14661471
// Non-simple annotations (subscript, attribute, parenthesized) are
14671472
// never compiled into __annotate__, so scanning them would create
1468-
// sub_tables that de-synchronize the annotation scope's sub_table index.
1473+
// sub_tables that cause mismatch in the annotation scope's sub_table index.
14691474
let is_simple_name = *simple && matches!(&**target, Expr::Name(_));
14701475
if is_simple_name {
14711476
self.scan_annotation(annotation)?;
1477+
} else {
1478+
// Still validate annotation for forbidden expressions
1479+
// (yield, await, named) even for non-simple targets.
1480+
let was_in_annotation = self.in_annotation;
1481+
self.in_annotation = true;
1482+
self.scan_expression(annotation, ExpressionContext::Load)?;
1483+
self.in_annotation = was_in_annotation;
14721484
}
14731485
if let Some(value) = value {
14741486
self.scan_expression(value, ExpressionContext::Load)?;

0 commit comments

Comments
 (0)