@@ -197,6 +197,17 @@ impl Node<CallExpressionKw> {
197
197
let fn_name = & self . callee ;
198
198
let callsite: SourceRange = self . into ( ) ;
199
199
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
+
200
211
// Evaluate the unlabeled first param, if any exists.
201
212
let unlabeled = if let Some ( ref arg_expr) = self . unlabeled {
202
213
let source_range = SourceRange :: from ( arg_expr. clone ( ) ) ;
@@ -247,17 +258,6 @@ impl Node<CallExpressionKw> {
247
258
exec_state. pipe_value ( ) . map ( |v| Arg :: new ( v. clone ( ) , callsite) ) ,
248
259
) ;
249
260
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
-
261
261
let return_value = fn_src
262
262
. call_kw ( Some ( fn_name. to_string ( ) ) , exec_state, ctx, args, callsite)
263
263
. await
0 commit comments