Skip to content

Commit f7e2a34

Browse files
committed
address review: parenthesized yield suite header
Walk through grouping parentheses before requiring yield after a suite-header colon. Assisted-by: Grok:grok-4.6
1 parent 73144c4 commit f7e2a34

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎crates/compiler/src/lib.rs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,15 +2784,27 @@ fn assignment_target_expr_range(source: &str, start: usize, end: usize) -> Optio
27842784
}
27852785
// `def f(): (yield bar)` — skip the suite header so the remaining
27862786
// text is the assignment target expression. Other colons (`x: int += 1`)
2787-
// are not suite headers for this diagnostic.
2787+
// are not suite headers for this diagnostic. Grouping parentheses may
2788+
// wrap the yield expression.
27882789
let colon = top_level_colon(bytes, target_start, target_end)?;
27892790
let after = skip_horizontal_whitespace(bytes, colon + 1);
2790-
if after >= target_end || !starts_identifier(bytes, after, b"yield") {
2791+
let yield_at = skip_opening_parentheses(bytes, after, target_end);
2792+
if yield_at >= target_end || !starts_identifier(bytes, yield_at, b"yield") {
27912793
return None;
27922794
}
27932795
Some((after, target_end))
27942796
}
27952797

2798+
fn skip_opening_parentheses(bytes: &[u8], mut index: usize, end: usize) -> usize {
2799+
loop {
2800+
index = skip_horizontal_whitespace(bytes, index);
2801+
if index >= end || bytes[index] != b'(' {
2802+
return index;
2803+
}
2804+
index += 1;
2805+
}
2806+
}
2807+
27962808
fn trim_target_range(bytes: &[u8], mut start: usize, mut end: usize) -> (usize, usize) {
27972809
while start < end
27982810
&& matches!(

0 commit comments

Comments
 (0)