Skip to content

Commit 09d849a

Browse files
committed
Distinguish MultipleStarArgs and InvalidStarArgs compile errors
1 parent 0ec86f1 commit 09d849a

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

compiler/src/compile.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ impl<O: OutputStream> Compiler<O> {
13741374
for (i, element) in elements.iter().enumerate() {
13751375
if let ast::ExpressionType::Starred { .. } = &element.node {
13761376
if seen_star {
1377-
return Err(self.error(CompileErrorType::StarArgs));
1377+
return Err(self.error(CompileErrorType::MultipleStarArgs));
13781378
} else {
13791379
seen_star = true;
13801380
self.emit(Instruction::UnpackEx {
@@ -1782,11 +1782,7 @@ impl<O: OutputStream> Compiler<O> {
17821782
self.compile_comprehension(kind, generators)?;
17831783
}
17841784
Starred { .. } => {
1785-
return Err(
1786-
self.error(CompileErrorType::SyntaxError(std::string::String::from(
1787-
"Invalid starred expression",
1788-
))),
1789-
);
1785+
return Err(self.error(CompileErrorType::InvalidStarExpr));
17901786
}
17911787
IfExpression { test, body, orelse } => {
17921788
let no_label = self.new_label();

compiler/src/error.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ pub enum CompileErrorType {
4747
Parse(ParseErrorType),
4848
SyntaxError(String),
4949
/// Multiple `*` detected
50-
StarArgs,
50+
MultipleStarArgs,
51+
/// Misplaced `*` expression
52+
InvalidStarExpr,
5153
/// Break statement outside of loop.
5254
InvalidBreak,
5355
/// Continue statement outside of loop.
@@ -97,7 +99,10 @@ impl fmt::Display for CompileError {
9799
CompileErrorType::ExpectExpr => "Expecting expression, got statement".to_owned(),
98100
CompileErrorType::Parse(err) => err.to_string(),
99101
CompileErrorType::SyntaxError(err) => err.to_string(),
100-
CompileErrorType::StarArgs => "Two starred expressions in assignment".to_owned(),
102+
CompileErrorType::MultipleStarArgs => {
103+
"two starred expressions in assignment".to_owned()
104+
}
105+
CompileErrorType::InvalidStarExpr => "can't use starred expression here".to_owned(),
101106
CompileErrorType::InvalidBreak => "'break' outside loop".to_owned(),
102107
CompileErrorType::InvalidContinue => "'continue' outside loop".to_owned(),
103108
CompileErrorType::InvalidReturn => "'return' outside function".to_owned(),

0 commit comments

Comments
 (0)