mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-17 10:05:23 +00:00
Distinguish MultipleStarArgs and InvalidStarArgs compile errors
This commit is contained in:
parent
3f2b414fcc
commit
a77e0b8587
2 changed files with 9 additions and 8 deletions
|
@ -1374,7 +1374,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
for (i, element) in elements.iter().enumerate() {
|
for (i, element) in elements.iter().enumerate() {
|
||||||
if let ast::ExpressionType::Starred { .. } = &element.node {
|
if let ast::ExpressionType::Starred { .. } = &element.node {
|
||||||
if seen_star {
|
if seen_star {
|
||||||
return Err(self.error(CompileErrorType::StarArgs));
|
return Err(self.error(CompileErrorType::MultipleStarArgs));
|
||||||
} else {
|
} else {
|
||||||
seen_star = true;
|
seen_star = true;
|
||||||
self.emit(Instruction::UnpackEx {
|
self.emit(Instruction::UnpackEx {
|
||||||
|
@ -1782,11 +1782,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
self.compile_comprehension(kind, generators)?;
|
self.compile_comprehension(kind, generators)?;
|
||||||
}
|
}
|
||||||
Starred { .. } => {
|
Starred { .. } => {
|
||||||
return Err(
|
return Err(self.error(CompileErrorType::InvalidStarExpr));
|
||||||
self.error(CompileErrorType::SyntaxError(std::string::String::from(
|
|
||||||
"Invalid starred expression",
|
|
||||||
))),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
IfExpression { test, body, orelse } => {
|
IfExpression { test, body, orelse } => {
|
||||||
let no_label = self.new_label();
|
let no_label = self.new_label();
|
||||||
|
|
|
@ -47,7 +47,9 @@ pub enum CompileErrorType {
|
||||||
Parse(ParseErrorType),
|
Parse(ParseErrorType),
|
||||||
SyntaxError(String),
|
SyntaxError(String),
|
||||||
/// Multiple `*` detected
|
/// Multiple `*` detected
|
||||||
StarArgs,
|
MultipleStarArgs,
|
||||||
|
/// Misplaced `*` expression
|
||||||
|
InvalidStarExpr,
|
||||||
/// Break statement outside of loop.
|
/// Break statement outside of loop.
|
||||||
InvalidBreak,
|
InvalidBreak,
|
||||||
/// Continue statement outside of loop.
|
/// Continue statement outside of loop.
|
||||||
|
@ -97,7 +99,10 @@ impl fmt::Display for CompileError {
|
||||||
CompileErrorType::ExpectExpr => "Expecting expression, got statement".to_owned(),
|
CompileErrorType::ExpectExpr => "Expecting expression, got statement".to_owned(),
|
||||||
CompileErrorType::Parse(err) => err.to_string(),
|
CompileErrorType::Parse(err) => err.to_string(),
|
||||||
CompileErrorType::SyntaxError(err) => err.to_string(),
|
CompileErrorType::SyntaxError(err) => err.to_string(),
|
||||||
CompileErrorType::StarArgs => "Two starred expressions in assignment".to_owned(),
|
CompileErrorType::MultipleStarArgs => {
|
||||||
|
"two starred expressions in assignment".to_owned()
|
||||||
|
}
|
||||||
|
CompileErrorType::InvalidStarExpr => "can't use starred expression here".to_owned(),
|
||||||
CompileErrorType::InvalidBreak => "'break' outside loop".to_owned(),
|
CompileErrorType::InvalidBreak => "'break' outside loop".to_owned(),
|
||||||
CompileErrorType::InvalidContinue => "'continue' outside loop".to_owned(),
|
CompileErrorType::InvalidContinue => "'continue' outside loop".to_owned(),
|
||||||
CompileErrorType::InvalidReturn => "'return' outside function".to_owned(),
|
CompileErrorType::InvalidReturn => "'return' outside function".to_owned(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue