Fix capturing bug

This commit is contained in:
Laurenz 2021-06-27 12:05:36 +02:00
parent 422b8e640f
commit f64c772b6d
3 changed files with 14 additions and 4 deletions

View File

@ -210,7 +210,7 @@ castable! {
AlignValue: "alignment",
}
/// ´box`: Place content in a rectangular box.
/// `box`: Place content in a rectangular box.
pub fn boxed(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
let width = args.named(ctx, "width");
let height = args.named(ctx, "height");
@ -221,7 +221,7 @@ pub fn boxed(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
})
}
/// block`: Place content in a block.
/// `block`: Place content in a block.
pub fn block(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
let body = args.eat(ctx).unwrap_or_default();
Value::template(move |ctx| {

View File

@ -183,10 +183,10 @@ visit! {
}
fn visit_let(v, node: &LetExpr) {
v.visit_binding(&node.binding);
if let Some(init) = &node.init {
v.visit_expr(&init);
}
v.visit_binding(&node.binding);
}
fn visit_if(v, node: &IfExpr) {
@ -203,6 +203,7 @@ visit! {
}
fn visit_for(v, node: &ForExpr) {
v.visit_expr(&node.iter);
match &node.pattern {
ForPattern::Value(value) => v.visit_binding(value),
ForPattern::KeyValue(key, value) => {
@ -210,7 +211,6 @@ visit! {
v.visit_binding(value);
}
}
v.visit_expr(&node.iter);
v.visit_expr(&node.body);
}

View File

@ -44,6 +44,16 @@
test(func(), error)
}
// Redefined variable.
{
let x = 1
let f() = {
let x = x + 2
x
}
test(f(), 3)
}
---
// Too few arguments.
{