Skip to content

Commit 3dad2f9

Browse files
committed
Fix callee execution order
1 parent 549a9be commit 3dad2f9

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

rust/kcl-lib/src/execution/fn_call.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,17 @@ impl Node<CallExpressionKw> {
197197
let fn_name = &self.callee;
198198
let callsite: SourceRange = self.into();
199199

200+
// Clone the function so that we can use a mutable reference to
201+
// exec_state.
202+
let func = fn_name.get_result(exec_state, ctx).await?.clone();
203+
204+
let Some(fn_src) = func.as_function() else {
205+
return Err(KclError::new_semantic(KclErrorDetails::new(
206+
"cannot call this because it isn't a function".to_string(),
207+
vec![callsite],
208+
)));
209+
};
210+
200211
// Evaluate the unlabeled first param, if any exists.
201212
let unlabeled = if let Some(ref arg_expr) = self.unlabeled {
202213
let source_range = SourceRange::from(arg_expr.clone());
@@ -247,17 +258,6 @@ impl Node<CallExpressionKw> {
247258
exec_state.pipe_value().map(|v| Arg::new(v.clone(), callsite)),
248259
);
249260

250-
// Clone the function so that we can use a mutable reference to
251-
// exec_state.
252-
let func = fn_name.get_result(exec_state, ctx).await?.clone();
253-
254-
let Some(fn_src) = func.as_function() else {
255-
return Err(KclError::new_semantic(KclErrorDetails::new(
256-
"cannot call this because it isn't a function".to_string(),
257-
vec![callsite],
258-
)));
259-
};
260-
261261
let return_value = fn_src
262262
.call_kw(Some(fn_name.to_string()), exec_state, ctx, args, callsite)
263263
.await
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This won't work, because `sketch001` is being referenced in its own definition.
22
sketch001 = startSketchOn(XY)
3-
|> startProfileAt([20, -20], sketch001)
3+
|> startProfile(sketch001, at = [20, -20])

0 commit comments

Comments
 (0)