Fix syntax error tests

This commit is contained in:
Noah committed 2020-03-21 00:35:36 -05:00
1 parent 8a30af8357
commit af25fbed39
5 files changed
+14 -29

No files matched your search

-29
View File
@@ -562,8 +562,6 @@ impl<O: OutputStream> Compiler<O> {
}
match value {
Some(v) => {
<<<<<<< Updated upstream
=======
if self.ctx.func == FunctionContext::AsyncFunction
&& self.current_output().is_generator()
{
@@ -572,7 +570,6 @@ impl<O: OutputStream> Compiler<O> {
statement.location.clone(),
));
}
>>>>>>> Stashed changes
self.compile_expression(v)?;
}
None => {
@@ -1658,16 +1655,7 @@ impl<O: OutputStream> Compiler<O> {
}
Await { value } => {
if self.ctx.func != FunctionContext::AsyncFunction {
<<<<<<< Updated upstream
return Err(CompileError {
statement: None,
error: CompileErrorType::InvalidAwait,
location: self.current_source_location.clone(),
source_path: None,
});
=======
return Err(self.error(CompileErrorType::InvalidAwait));
>>>>>>> Stashed changes
}
self.compile_expression(value)?;
self.emit(Instruction::GetAwaitable);
@@ -1679,27 +1667,10 @@ impl<O: OutputStream> Compiler<O> {
YieldFrom { value } => {
match self.ctx.func {
FunctionContext::NoFunction => {
<<<<<<< Updated upstream
return Err(CompileError {
statement: None,
error: CompileErrorType::InvalidYieldFrom,
location: self.current_source_location.clone(),
source_path: None,
})
}
FunctionContext::AsyncFunction => {
return Err(CompileError {
statement: None,
error: CompileErrorType::AsyncYieldFrom,
location: self.current_source_location.clone(),
source_path: None,
})
=======
return Err(self.error(CompileErrorType::InvalidYieldFrom))
}
FunctionContext::AsyncFunction => {
return Err(self.error(CompileErrorType::AsyncYieldFrom))
>>>>>>> Stashed changes
}
FunctionContext::Function => {}
}
+4
View File
@@ -57,6 +57,7 @@ pub enum CompileErrorType {
InvalidYieldFrom,
InvalidAwait,
AsyncYieldFrom,
AsyncReturnValue,
}
impl CompileError {
@@ -102,6 +103,9 @@ impl fmt::Display for CompileError {
CompileErrorType::InvalidYieldFrom => "'yield from' outside function".to_owned(),
CompileErrorType::InvalidAwait => "'await' outside async function".to_owned(),
CompileErrorType::AsyncYieldFrom => "'yield from' inside async function".to_owned(),
CompileErrorType::AsyncReturnValue => {
"'return' with value inside async generator".to_owned()
}
};
if let Some(statement) = &self.statement {
+5
View File
@@ -7,6 +7,8 @@ pub trait OutputStream: From<CodeObject> + Into<CodeObject> {
fn set_label(&mut self, label: Label);
/// Mark the inner CodeObject as a generator
fn mark_generator(&mut self);
/// Check to see if the inner CodeObject is a generator
fn is_generator(&self) -> bool;
}
pub struct CodeObjectStream {
@@ -36,4 +38,7 @@ impl OutputStream for CodeObjectStream {
fn mark_generator(&mut self) {
self.code.flags |= CodeFlags::IS_GENERATOR;
}
fn is_generator(&self) -> bool {
self.code.flags.contains(CodeFlags::IS_GENERATOR)
}
}
+3
View File
@@ -112,6 +112,9 @@ where
fn mark_generator(&mut self) {
self.inner.mark_generator()
}
fn is_generator(&self) -> bool {
self.inner.is_generator()
}
}
impl<O: OutputStream> OptimizationBuffer for PeepholeOptimizer<O> {
+2
View File
@@ -685,6 +685,8 @@ where
tabs = 0;
}
None => {
spaces = 0;
tabs = 0;
break;
}
_ => {