From f64c772b6d969fa3aa1a7391a3d8118b21430434 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 27 Jun 2021 12:05:36 +0200 Subject: [PATCH] Fix capturing bug --- src/library/layout.rs | 4 ++-- src/syntax/visit.rs | 4 ++-- tests/typ/code/closure.typ | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/library/layout.rs b/src/library/layout.rs index 27b2e743b..08924bad4 100644 --- a/src/library/layout.rs +++ b/src/library/layout.rs @@ -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| { diff --git a/src/syntax/visit.rs b/src/syntax/visit.rs index cf819ef06..524183613 100644 --- a/src/syntax/visit.rs +++ b/src/syntax/visit.rs @@ -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); } diff --git a/tests/typ/code/closure.typ b/tests/typ/code/closure.typ index 86a6f6328..402df7997 100644 --- a/tests/typ/code/closure.typ +++ b/tests/typ/code/closure.typ @@ -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. {