(
&self,
localsplus_idx: usize,
vm: &VirtualMachine,
)
| 1933 | } |
| 1934 | |
| 1935 | fn unbound_cell_exception( |
| 1936 | &self, |
| 1937 | localsplus_idx: usize, |
| 1938 | vm: &VirtualMachine, |
| 1939 | ) -> PyBaseExceptionRef { |
| 1940 | use rustpython_compiler_core::bytecode::CO_FAST_FREE; |
| 1941 | let kind = self |
| 1942 | .code |
| 1943 | .localspluskinds |
| 1944 | .get(localsplus_idx) |
| 1945 | .copied() |
| 1946 | .unwrap_or(0); |
| 1947 | if kind & CO_FAST_FREE != 0 { |
| 1948 | let name = self.localsplus_name(localsplus_idx); |
| 1949 | vm.new_name_error( |
| 1950 | format!("cannot access free variable '{name}' where it is not associated with a value in enclosing scope"), |
| 1951 | name.to_owned(), |
| 1952 | ) |
| 1953 | } else { |
| 1954 | // Both merged cells (LOCAL|CELL) and non-merged cells get unbound local error |
| 1955 | let name = self.localsplus_name(localsplus_idx); |
| 1956 | vm.new_exception_msg( |
| 1957 | vm.ctx.exceptions.unbound_local_error.to_owned(), |
| 1958 | format!("local variable '{name}' referenced before assignment").into(), |
| 1959 | ) |
| 1960 | } |
| 1961 | } |
| 1962 | |
| 1963 | /// Get the variable name for a localsplus index. |
| 1964 | fn localsplus_name(&self, idx: usize) -> &'static PyStrInterned { |
no test coverage detected