mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Fix capturing bug
This commit is contained in:
parent
422b8e640f
commit
f64c772b6d
@ -210,7 +210,7 @@ castable! {
|
|||||||
AlignValue: "alignment",
|
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 {
|
pub fn boxed(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||||
let width = args.named(ctx, "width");
|
let width = args.named(ctx, "width");
|
||||||
let height = args.named(ctx, "height");
|
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 {
|
pub fn block(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||||
let body = args.eat(ctx).unwrap_or_default();
|
let body = args.eat(ctx).unwrap_or_default();
|
||||||
Value::template(move |ctx| {
|
Value::template(move |ctx| {
|
||||||
|
@ -183,10 +183,10 @@ visit! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_let(v, node: &LetExpr) {
|
fn visit_let(v, node: &LetExpr) {
|
||||||
v.visit_binding(&node.binding);
|
|
||||||
if let Some(init) = &node.init {
|
if let Some(init) = &node.init {
|
||||||
v.visit_expr(&init);
|
v.visit_expr(&init);
|
||||||
}
|
}
|
||||||
|
v.visit_binding(&node.binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_if(v, node: &IfExpr) {
|
fn visit_if(v, node: &IfExpr) {
|
||||||
@ -203,6 +203,7 @@ visit! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_for(v, node: &ForExpr) {
|
fn visit_for(v, node: &ForExpr) {
|
||||||
|
v.visit_expr(&node.iter);
|
||||||
match &node.pattern {
|
match &node.pattern {
|
||||||
ForPattern::Value(value) => v.visit_binding(value),
|
ForPattern::Value(value) => v.visit_binding(value),
|
||||||
ForPattern::KeyValue(key, value) => {
|
ForPattern::KeyValue(key, value) => {
|
||||||
@ -210,7 +211,6 @@ visit! {
|
|||||||
v.visit_binding(value);
|
v.visit_binding(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v.visit_expr(&node.iter);
|
|
||||||
v.visit_expr(&node.body);
|
v.visit_expr(&node.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,16 @@
|
|||||||
test(func(), error)
|
test(func(), error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Redefined variable.
|
||||||
|
{
|
||||||
|
let x = 1
|
||||||
|
let f() = {
|
||||||
|
let x = x + 2
|
||||||
|
x
|
||||||
|
}
|
||||||
|
test(f(), 3)
|
||||||
|
}
|
||||||
|
|
||||||
---
|
---
|
||||||
// Too few arguments.
|
// Too few arguments.
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user