Check whether a write access at `offset` for variable `name` is actually a parameter declaration of a nested closure or arrow function frame. Closure and arrow function parameters are declared at offsets that fall between `parent.start` and `child.start` — the parent frame body contains them, but `is_in_nested_frame` does not catch them because the child frame's body hasn't started yet. We must
(
name: &str,
offset: u32,
parent: &crate::scope_collector::Frame,
frames: &[crate::scope_collector::Frame],
)
| 486 | /// because the child frame's body hasn't started yet. We must not |
| 487 | /// let the parent frame claim these parameter writes as its own. |
| 488 | fn is_nested_frame_parameter( |
| 489 | name: &str, |
| 490 | offset: u32, |
| 491 | parent: &crate::scope_collector::Frame, |
| 492 | frames: &[crate::scope_collector::Frame], |
| 493 | ) -> bool { |
| 494 | frames.iter().any(|f| { |
| 495 | // Only consider frames nested within the parent. |
| 496 | f.start > parent.start |
| 497 | && f.end < parent.end |
| 498 | // The parameter declaration is between the parent body start |
| 499 | // and the child body start (e.g. in the parameter list of a |
| 500 | // closure or arrow function). |
| 501 | && offset < f.start |
| 502 | && offset > parent.start |
| 503 | // Check that this variable is actually a parameter of this frame. |
| 504 | && f.parameters.iter().any(|p| p.as_str() == name) |
| 505 | }) |
| 506 | } |
| 507 | |
| 508 | #[cfg(test)] |
| 509 | mod tests { |
no test coverage detected