mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
Fix capturing bug
This commit is contained in:
parent
422b8e640f
commit
f64c772b6d
@ -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| {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user