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:
		
							parent
							
								
									ec7ee9626f
								
							
						
					
					
						commit
						a4c18c37dc
					
				
					 1 changed files with 28 additions and 28 deletions
				
			
		| 
						 | 
				
			
			@ -460,36 +460,36 @@ fn compile_pipe_call<'a>(
 | 
			
		|||
    left: NodeId,
 | 
			
		||||
    call: NodeId,
 | 
			
		||||
) -> CompileResult {
 | 
			
		||||
    if src.ast.kind(call) != NodeKind::Call {
 | 
			
		||||
        c.emit(Diagnostic::error(
 | 
			
		||||
            src.ast.span(call),
 | 
			
		||||
            "the right side of a pipe `|` must be a function call",
 | 
			
		||||
        ));
 | 
			
		||||
        return Ok(());
 | 
			
		||||
    match src.ast.kind(call) {
 | 
			
		||||
        NodeKind::Call => {
 | 
			
		||||
            let mut walk = src.ast.walk(call);
 | 
			
		||||
            let Some(func) = walk.node() else {
 | 
			
		||||
                return Ok(());
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            compile_expr(c, src, left)?;
 | 
			
		||||
            let mut argument_count = 1;
 | 
			
		||||
            while let Some(arg) = walk.node() {
 | 
			
		||||
                compile_expr(c, src, arg)?;
 | 
			
		||||
                argument_count += 1;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            let argument_count = u8::try_from(argument_count).unwrap_or_else(|_| {
 | 
			
		||||
                c.emit(Diagnostic::error(
 | 
			
		||||
                    src.ast.span(call),
 | 
			
		||||
                    "function call has too many arguments",
 | 
			
		||||
                ));
 | 
			
		||||
                0
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            emit_nary_call(c, src, func, argument_count)?;
 | 
			
		||||
        }
 | 
			
		||||
        _ => {
 | 
			
		||||
            compile_expr(c, src, left)?;
 | 
			
		||||
            emit_nary_call(c, src, call, 1)?;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let mut walk = src.ast.walk(call);
 | 
			
		||||
    let Some(func) = walk.node() else {
 | 
			
		||||
        return Ok(());
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    compile_expr(c, src, left)?;
 | 
			
		||||
    let mut argument_count = 1;
 | 
			
		||||
    while let Some(arg) = walk.node() {
 | 
			
		||||
        compile_expr(c, src, arg)?;
 | 
			
		||||
        argument_count += 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let argument_count = u8::try_from(argument_count).unwrap_or_else(|_| {
 | 
			
		||||
        c.emit(Diagnostic::error(
 | 
			
		||||
            src.ast.span(call),
 | 
			
		||||
            "function call has too many arguments",
 | 
			
		||||
        ));
 | 
			
		||||
        0
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    emit_nary_call(c, src, func, argument_count)?;
 | 
			
		||||
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue