KCL bugfix: CallExpressionKw was not usable as math operand (#6460)
Closes https://github.com/KittyCAD/modeling-app/issues/4992
This commit is contained in:
@ -2074,6 +2074,7 @@ fn possible_operands(i: &mut TokenSlice) -> PResult<Expr> {
|
|||||||
member_expression.map(Box::new).map(Expr::MemberExpression),
|
member_expression.map(Box::new).map(Expr::MemberExpression),
|
||||||
literal.map(Expr::Literal),
|
literal.map(Expr::Literal),
|
||||||
fn_call.map(Box::new).map(Expr::CallExpression),
|
fn_call.map(Box::new).map(Expr::CallExpression),
|
||||||
|
fn_call_kw.map(Box::new).map(Expr::CallExpressionKw),
|
||||||
name.map(Box::new).map(Expr::Name),
|
name.map(Box::new).map(Expr::Name),
|
||||||
binary_expr_in_parens.map(Box::new).map(Expr::BinaryExpression),
|
binary_expr_in_parens.map(Box::new).map(Expr::BinaryExpression),
|
||||||
unnecessarily_bracketed,
|
unnecessarily_bracketed,
|
||||||
@ -3254,6 +3255,14 @@ mod tests {
|
|||||||
assert_eq!(err.message, "Unexpected end of file. The compiler expected )");
|
assert_eq!(err.message, "Unexpected end of file. The compiler expected )");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn kw_call_as_operand() {
|
||||||
|
let tokens = crate::parsing::token::lex("f(x = 1)", ModuleId::default()).unwrap();
|
||||||
|
let tokens = tokens.as_slice();
|
||||||
|
let op = operand.parse(tokens).unwrap();
|
||||||
|
println!("{op:#?}");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn weird_program_just_a_pipe() {
|
fn weird_program_just_a_pipe() {
|
||||||
let tokens = crate::parsing::token::lex("|", ModuleId::default()).unwrap();
|
let tokens = crate::parsing::token::lex("|", ModuleId::default()).unwrap();
|
||||||
@ -5389,6 +5398,7 @@ my14 = 4 ^ 2 - 3 ^ 2 * 2
|
|||||||
bar = x,
|
bar = x,
|
||||||
)"#
|
)"#
|
||||||
);
|
);
|
||||||
|
snapshot_test!(kw_function_in_binary_op, r#"val = f(x = 1) + 1"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
|
|||||||
@ -0,0 +1,99 @@
|
|||||||
|
---
|
||||||
|
source: kcl-lib/src/parsing/parser.rs
|
||||||
|
expression: actual
|
||||||
|
---
|
||||||
|
{
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"commentStart": 0,
|
||||||
|
"declaration": {
|
||||||
|
"commentStart": 0,
|
||||||
|
"end": 18,
|
||||||
|
"id": {
|
||||||
|
"commentStart": 0,
|
||||||
|
"end": 3,
|
||||||
|
"name": "val",
|
||||||
|
"start": 0,
|
||||||
|
"type": "Identifier"
|
||||||
|
},
|
||||||
|
"init": {
|
||||||
|
"commentStart": 6,
|
||||||
|
"end": 18,
|
||||||
|
"left": {
|
||||||
|
"arguments": [
|
||||||
|
{
|
||||||
|
"type": "LabeledArg",
|
||||||
|
"label": {
|
||||||
|
"commentStart": 8,
|
||||||
|
"end": 9,
|
||||||
|
"name": "x",
|
||||||
|
"start": 8,
|
||||||
|
"type": "Identifier"
|
||||||
|
},
|
||||||
|
"arg": {
|
||||||
|
"commentStart": 12,
|
||||||
|
"end": 13,
|
||||||
|
"raw": "1",
|
||||||
|
"start": 12,
|
||||||
|
"type": "Literal",
|
||||||
|
"type": "Literal",
|
||||||
|
"value": {
|
||||||
|
"value": 1.0,
|
||||||
|
"suffix": "None"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"callee": {
|
||||||
|
"abs_path": false,
|
||||||
|
"commentStart": 6,
|
||||||
|
"end": 7,
|
||||||
|
"name": {
|
||||||
|
"commentStart": 6,
|
||||||
|
"end": 7,
|
||||||
|
"name": "f",
|
||||||
|
"start": 6,
|
||||||
|
"type": "Identifier"
|
||||||
|
},
|
||||||
|
"path": [],
|
||||||
|
"start": 6,
|
||||||
|
"type": "Name"
|
||||||
|
},
|
||||||
|
"commentStart": 6,
|
||||||
|
"end": 14,
|
||||||
|
"start": 6,
|
||||||
|
"type": "CallExpressionKw",
|
||||||
|
"type": "CallExpressionKw",
|
||||||
|
"unlabeled": null
|
||||||
|
},
|
||||||
|
"operator": "+",
|
||||||
|
"right": {
|
||||||
|
"commentStart": 17,
|
||||||
|
"end": 18,
|
||||||
|
"raw": "1",
|
||||||
|
"start": 17,
|
||||||
|
"type": "Literal",
|
||||||
|
"type": "Literal",
|
||||||
|
"value": {
|
||||||
|
"value": 1.0,
|
||||||
|
"suffix": "None"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"start": 6,
|
||||||
|
"type": "BinaryExpression",
|
||||||
|
"type": "BinaryExpression"
|
||||||
|
},
|
||||||
|
"start": 0,
|
||||||
|
"type": "VariableDeclarator"
|
||||||
|
},
|
||||||
|
"end": 18,
|
||||||
|
"kind": "const",
|
||||||
|
"start": 0,
|
||||||
|
"type": "VariableDeclaration",
|
||||||
|
"type": "VariableDeclaration"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"commentStart": 0,
|
||||||
|
"end": 18,
|
||||||
|
"start": 0
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user