-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Description
The following code crashes:
#let f(fn) = {
context (size: none) => {
if size == none { size = text.size }
fn(size)
}()
}
#f((size) => [
Text size is #size
])
with
thread 'main' panicked at crates/typst-eval/src/call.rs:242:47:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I have no experience with the compiler so my investigations were very crude and limited, however here are some things which might be related:
When the closure is parenthesised, it compiles and renders as expected
// this renders correctly
#let f(fn) = {
context ((size: none) => {
if size == none { size = text.size }
fn(size)
})()
}
#f((size) => [
Text size is #size
])
A similar behaviour can be observed without context but which doesn't lead to a crash (I am unsure whether this is an expected behaviour or not, and if not, whether this ought to be a separate issue, I apologize).
Consider the following:
#{
(() => {
[ Foo ]
})()
}
#{
() => {
[ Bar ]
}()
}
This is rendered as:
Foo
(..) => ..
In fact the second closure doesn't seem to be evaluated since the code
#{
(x) => {
[ Bar ]
}()
}
also renders as (..) => ..
whereas
#{
((x) => {
[ Foo ]
})()
}
raises a missing argument error as expected.
This parenthesis behaviour is quite confusing since when the closure is stored in a variable, there is no difference in behaviour between parenthesised and not parenthesised.
#{
let foo = () => {
[ Foo ]
}
foo()
}
#{
let foo = (() => {
[ Bar ]
})
foo()
}
renders as
Foo
Bar
as expected.
Reproduction URL
No response
Operating system
Linux
Typst version
- I am using the latest version of Typst