mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-20 19:45:21 +00:00
Consolidate error handling for builtin "constants" mutations
Co-authored-by: Jeong YunWon <youknowone@users.noreply.github.com>
This commit is contained in:
parent
be92bc5243
commit
e038799297
1 changed files with 6 additions and 13 deletions
|
@ -396,19 +396,12 @@ impl Compiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_forbidden_name(&self, name: &str, usage: NameUsage) -> CompileResult<()> {
|
fn check_forbidden_name(&self, name: &str, usage: NameUsage) -> CompileResult<()> {
|
||||||
if usage == NameUsage::Store && is_forbidden_name(name) {
|
let msg = match usage {
|
||||||
return Err(self.error(CompileErrorType::SyntaxError(format!(
|
NameUsage::Store if is_forbidden_name(name) => "cannot assign to",
|
||||||
"cannot assign to {}",
|
NameUsage::Delete if is_forbidden_name(name) => "cannot delete",
|
||||||
name
|
_ => return Ok(()),
|
||||||
))));
|
};
|
||||||
}
|
Err(self.error(CompileErrorType::SyntaxError(format!("{} {}", msg, name))))
|
||||||
if usage == NameUsage::Delete && is_forbidden_name(name) {
|
|
||||||
return Err(self.error(CompileErrorType::SyntaxError(format!(
|
|
||||||
"cannot delete {}",
|
|
||||||
name
|
|
||||||
))));
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_name(&mut self, name: &str, usage: NameUsage) -> CompileResult<()> {
|
fn compile_name(&mut self, name: &str, usage: NameUsage) -> CompileResult<()> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue