(
&mut self,
name: &str,
)
| 1664 | } |
| 1665 | |
| 1666 | fn resolve_upvalue( |
| 1667 | &mut self, |
| 1668 | name: &str, |
| 1669 | ) -> Result<Option<(u8, isize, Mutability)>, &'static str> { |
| 1670 | if let Some((index, depth, mutability)) = self |
| 1671 | .enclosing |
| 1672 | .as_mut() |
| 1673 | .and_then(|enclosing| enclosing.resolve_local(name)) |
| 1674 | { |
| 1675 | if let Some(enclosing) = self.enclosing.as_mut() { |
| 1676 | // When resolving an identifier, if we end up creating an upvalue for |
| 1677 | // a local variable, we mark it as captured. |
| 1678 | enclosing.locals[index as usize].is_captured = true; |
| 1679 | } |
| 1680 | let index = self.add_upvalue(index as usize, true)?; |
| 1681 | return Ok(Some((index as u8, depth, mutability))); |
| 1682 | } else if let Some((index, depth, mutability)) = self |
| 1683 | .enclosing |
| 1684 | .as_mut() |
| 1685 | .and_then(|enclosing| enclosing.resolve_upvalue(name).ok()) |
| 1686 | .flatten() |
| 1687 | { |
| 1688 | let index = self.add_upvalue(index as usize, false)?; |
| 1689 | return Ok(Some((index as u8, depth, mutability))); |
| 1690 | } |
| 1691 | |
| 1692 | Ok(None) |
| 1693 | } |
| 1694 | |
| 1695 | fn add_upvalue(&mut self, index: usize, is_local: bool) -> Result<usize, &'static str> { |
| 1696 | let upvalue_index = self.function.upvalues.len(); |
no test coverage detected