Fix syntax error tests

This commit is contained in:
Noah 2020-03-05 00:57:05 -06:00
parent d5b9e6b93a
commit 7d6d5ff907
4 changed files with 12 additions and 29 deletions

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 => {}
}

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 {

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)
}
}

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> {