Show warnings from eval

This commit is contained in:
+merlan #flirora 2025-03-26 16:31:38 -04:00
parent 1f1c133878
commit 6e8ce9ebd5
5 changed files with 25 additions and 5 deletions

View File

@ -105,7 +105,7 @@ pub fn eval_string(
span: Span,
mode: EvalMode,
scope: Scope,
) -> SourceResult<Value> {
) -> 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.

View File

@ -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)
}

View File

@ -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))
}

View File

@ -59,7 +59,7 @@ routines! {
span: Span,
mode: EvalMode,
scope: Scope,
) -> SourceResult<Value>
) -> SourceResult<(Value, Sink)>
/// Call the closure in the context with the arguments.
fn eval_closure(

View File

@ -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")