Fix bug that disabled the creation of recursive functions
...oops. The introduction and usage of `Compiler::emit_assign` deferred the declaration of a name to be declared *after* the RHS of an assignment had been evaluated. Normally, this is not a problem because you shouldn't be using the LHS that you're assigning in the RHS expression... except when you're defining a function. This has been enabled for functions *only* and well be enabled for other types as necessary. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -588,6 +588,22 @@ impl StmtVisitor for Compiler<'_> {
|
||||
match stmt.op.kind {
|
||||
// normal assignment
|
||||
TokenKind::Eq => {
|
||||
// Insert the name beforehand, but only if we're compiling a function
|
||||
// I think this is the only instance where we care about inserting a name before
|
||||
// it's used
|
||||
if stmt
|
||||
.rhs
|
||||
.as_any_ref()
|
||||
.downcast_ref::<FunctionExpr>()
|
||||
.is_some()
|
||||
{
|
||||
if self.is_global_scope() {
|
||||
self.insert_global(name)?;
|
||||
} else if self.get_local(name).is_none() {
|
||||
self.insert_local(name.to_string())?;
|
||||
}
|
||||
}
|
||||
|
||||
// compile RHS
|
||||
self.compile_expr(&stmt.rhs)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user