Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
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.
  • Loading branch information
youknowone committed Mar 2, 2026
commit 8b61e74cbdb0973eeff7801a7149366df97a7935
14 changes: 13 additions & 1 deletion crates/codegen/src/symboltable.rs
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 @@ -1465,10 +1470,17 @@ impl SymbolTableBuilder {
// 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 de-synchronize the annotation scope's sub_table index.
// 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;
self.scan_expression(annotation, ExpressionContext::Load)?;
self.in_annotation = was_in_annotation;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if let Some(value) = value {
self.scan_expression(value, ExpressionContext::Load)?;
Expand Down
Loading