diff --git a/crates/typst-eval/src/lib.rs b/crates/typst-eval/src/lib.rs index 5eae7c1df..97bedf55e 100644 --- a/crates/typst-eval/src/lib.rs +++ b/crates/typst-eval/src/lib.rs @@ -105,7 +105,7 @@ pub fn eval_string( span: Span, mode: EvalMode, scope: Scope, -) -> SourceResult { +) -> SourceResult<(Value, Sink)> { let mut root = match mode { EvalMode::Code => parse_code(string), EvalMode::Markup => parse(string), @@ -158,7 +158,7 @@ pub fn eval_string( bail!(flow.forbidden()); } - Ok(output) + Ok((output, sink)) } /// Evaluate an expression. diff --git a/crates/typst-library/src/foundations/mod.rs b/crates/typst-library/src/foundations/mod.rs index 8e3aa060d..651fe1a62 100644 --- a/crates/typst-library/src/foundations/mod.rs +++ b/crates/typst-library/src/foundations/mod.rs @@ -297,5 +297,18 @@ pub fn eval( for (key, value) in dict { scope.bind(key.into(), Binding::new(value, span)); } - (engine.routines.eval_string)(engine.routines, engine.world, &text, span, mode, scope) + let (result, sink) = (engine.routines.eval_string)( + engine.routines, + engine.world, + &text, + span, + mode, + scope, + )?; + + for warning in sink.warnings() { + engine.sink.warn(warning); + } + + Ok(result) } diff --git a/crates/typst-library/src/model/bibliography.rs b/crates/typst-library/src/model/bibliography.rs index b11c61789..085d06c44 100644 --- a/crates/typst-library/src/model/bibliography.rs +++ b/crates/typst-library/src/model/bibliography.rs @@ -1004,7 +1004,8 @@ impl ElemRenderer<'_> { EvalMode::Math, Scope::new(), ) - .map(Value::display) + // TODO: propagate warnings + .map(|(result, _sink)| Value::display(result)) .unwrap_or_else(|_| TextElem::packed(math).spanned(self.span)) } diff --git a/crates/typst-library/src/routines.rs b/crates/typst-library/src/routines.rs index b283052a4..e7f1a1f15 100644 --- a/crates/typst-library/src/routines.rs +++ b/crates/typst-library/src/routines.rs @@ -59,7 +59,7 @@ routines! { span: Span, mode: EvalMode, scope: Scope, - ) -> SourceResult + ) -> SourceResult<(Value, Sink)> /// Call the closure in the context with the arguments. fn eval_closure( diff --git a/tests/suite/foundations/eval.typ b/tests/suite/foundations/eval.typ index f85146b23..85f43911c 100644 --- a/tests/suite/foundations/eval.typ +++ b/tests/suite/foundations/eval.typ @@ -52,3 +52,9 @@ _Tiger!_ #eval(mode: "math", "f(a) = cases(a + b\, space space x >= 3,a + b\, space space x = 5)") $f(a) = cases(a + b\, space space x >= 3,a + b\, space space x = 5)$ + +--- issue-6067-eval-warnings --- +// Test that eval shows warnings from the executed code. +// Warning: 7-11 no text within stars +// Hint: 7-11 using multiple consecutive stars (e.g. **) has no additional effect +#eval("**", mode: "markup")