h1: make | operator work with anything other than syntactic calls (in which case it just calls the value)

in case you call a function to get a function, parenthesise it

    1 | getFunction ()   -- getFunction 1 ()
    1 | (getFunction ()) -- (getFunction ()) 1
This commit is contained in:
りき萌 2025-09-03 16:57:10 +02:00
parent ec7ee9626f
commit a4c18c37dc

View file

@ -460,14 +460,8 @@ fn compile_pipe_call<'a>(
left: NodeId, left: NodeId,
call: NodeId, call: NodeId,
) -> CompileResult { ) -> CompileResult {
if src.ast.kind(call) != NodeKind::Call { match src.ast.kind(call) {
c.emit(Diagnostic::error( NodeKind::Call => {
src.ast.span(call),
"the right side of a pipe `|` must be a function call",
));
return Ok(());
}
let mut walk = src.ast.walk(call); let mut walk = src.ast.walk(call);
let Some(func) = walk.node() else { let Some(func) = walk.node() else {
return Ok(()); return Ok(());
@ -489,6 +483,12 @@ fn compile_pipe_call<'a>(
}); });
emit_nary_call(c, src, func, argument_count)?; emit_nary_call(c, src, func, argument_count)?;
}
_ => {
compile_expr(c, src, left)?;
emit_nary_call(c, src, call, 1)?;
}
}
Ok(()) Ok(())
} }