Skip to content

Commit af25fbe

Browse files
committed
Fix syntax error tests
1 parent 8a30af8 commit af25fbe

File tree

5 files changed

+14
-29
lines changed

5 files changed

+14
-29
lines changed

compiler/src/compile.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,6 @@ impl<O: OutputStream> Compiler<O> {
562562
}
563563
match value {
564564
Some(v) => {
565-
<<<<<<< Updated upstream
566-
=======
567565
if self.ctx.func == FunctionContext::AsyncFunction
568566
&& self.current_output().is_generator()
569567
{
@@ -572,7 +570,6 @@ impl<O: OutputStream> Compiler<O> {
572570
statement.location.clone(),
573571
));
574572
}
575-
>>>>>>> Stashed changes
576573
self.compile_expression(v)?;
577574
}
578575
None => {
@@ -1658,16 +1655,7 @@ impl<O: OutputStream> Compiler<O> {
16581655
}
16591656
Await { value } => {
16601657
if self.ctx.func != FunctionContext::AsyncFunction {
1661-
<<<<<<< Updated upstream
1662-
return Err(CompileError {
1663-
statement: None,
1664-
error: CompileErrorType::InvalidAwait,
1665-
location: self.current_source_location.clone(),
1666-
source_path: None,
1667-
});
1668-
=======
16691658
return Err(self.error(CompileErrorType::InvalidAwait));
1670-
>>>>>>> Stashed changes
16711659
}
16721660
self.compile_expression(value)?;
16731661
self.emit(Instruction::GetAwaitable);
@@ -1679,27 +1667,10 @@ impl<O: OutputStream> Compiler<O> {
16791667
YieldFrom { value } => {
16801668
match self.ctx.func {
16811669
FunctionContext::NoFunction => {
1682-
<<<<<<< Updated upstream
1683-
return Err(CompileError {
1684-
statement: None,
1685-
error: CompileErrorType::InvalidYieldFrom,
1686-
location: self.current_source_location.clone(),
1687-
source_path: None,
1688-
})
1689-
}
1690-
FunctionContext::AsyncFunction => {
1691-
return Err(CompileError {
1692-
statement: None,
1693-
error: CompileErrorType::AsyncYieldFrom,
1694-
location: self.current_source_location.clone(),
1695-
source_path: None,
1696-
})
1697-
=======
16981670
return Err(self.error(CompileErrorType::InvalidYieldFrom))
16991671
}
17001672
FunctionContext::AsyncFunction => {
17011673
return Err(self.error(CompileErrorType::AsyncYieldFrom))
1702-
>>>>>>> Stashed changes
17031674
}
17041675
FunctionContext::Function => {}
17051676
}

compiler/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub enum CompileErrorType {
5757
InvalidYieldFrom,
5858
InvalidAwait,
5959
AsyncYieldFrom,
60+
AsyncReturnValue,
6061
}
6162

6263
impl CompileError {
@@ -102,6 +103,9 @@ impl fmt::Display for CompileError {
102103
CompileErrorType::InvalidYieldFrom => "'yield from' outside function".to_owned(),
103104
CompileErrorType::InvalidAwait => "'await' outside async function".to_owned(),
104105
CompileErrorType::AsyncYieldFrom => "'yield from' inside async function".to_owned(),
106+
CompileErrorType::AsyncReturnValue => {
107+
"'return' with value inside async generator".to_owned()
108+
}
105109
};
106110

107111
if let Some(statement) = &self.statement {

compiler/src/output_stream.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ pub trait OutputStream: From<CodeObject> + Into<CodeObject> {
77
fn set_label(&mut self, label: Label);
88
/// Mark the inner CodeObject as a generator
99
fn mark_generator(&mut self);
10+
/// Check to see if the inner CodeObject is a generator
11+
fn is_generator(&self) -> bool;
1012
}
1113

1214
pub struct CodeObjectStream {
@@ -36,4 +38,7 @@ impl OutputStream for CodeObjectStream {
3638
fn mark_generator(&mut self) {
3739
self.code.flags |= CodeFlags::IS_GENERATOR;
3840
}
41+
fn is_generator(&self) -> bool {
42+
self.code.flags.contains(CodeFlags::IS_GENERATOR)
43+
}
3944
}

compiler/src/peephole.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ where
112112
fn mark_generator(&mut self) {
113113
self.inner.mark_generator()
114114
}
115+
fn is_generator(&self) -> bool {
116+
self.inner.is_generator()
117+
}
115118
}
116119

117120
impl<O: OutputStream> OptimizationBuffer for PeepholeOptimizer<O> {

parser/src/lexer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,8 @@ where
685685
tabs = 0;
686686
}
687687
None => {
688+
spaces = 0;
689+
tabs = 0;
688690
break;
689691
}
690692
_ => {

0 commit comments

Comments
 (0)