@@ -3267,19 +3267,12 @@ CHECK_FUNC(insert_directive, AstDirectiveInsert** pinsert, b32 expected_expressi
3267
3267
ERROR (code_block -> token -> pos , "Here is the code block being unquoted." );
3268
3268
}
3269
3269
3270
-
3271
- // HACK when cloning the inner part of a code block, we have to be able to handle
3272
- // inline functions (lambdas) that are polymorphic or have captures. With either
3273
- // of these things, we have to clone the functions so any closures/polyvars referenced
3274
- // in them can be resolved correctly. To do this tho, we have to artificially increase
3275
- // the clone depth to make the cloner think we are one layer deeper than we actually
3276
- // are to fall into the code path where we clone the body of the function.
3277
- context -> cloner .clone_depth ++ ;
3270
+ context -> cloner .cloning_code_block = 1 ;
3278
3271
bh_arr (AstNode * ) captured_entities = NULL ;
3279
- bh_arr_new (context -> ast_alloc , captured_entities , 2 );
3272
+ bh_arr_new (context -> gp_alloc , captured_entities , 2 );
3280
3273
AstNode * cloned_block = ast_clone_with_captured_entities (context , code_block -> code , & captured_entities );
3281
3274
cloned_block -> next = insert -> next ;
3282
- context -> cloner .clone_depth -- ;
3275
+ context -> cloner .cloning_code_block = 0 ;
3283
3276
3284
3277
bh_arr_each (AstNode * , pnode , captured_entities ) {
3285
3278
add_entities_for_node (
@@ -3291,6 +3284,8 @@ CHECK_FUNC(insert_directive, AstDirectiveInsert** pinsert, b32 expected_expressi
3291
3284
);
3292
3285
}
3293
3286
3287
+ bh_arr_free (captured_entities );
3288
+
3294
3289
i32 skip_scope_index = get_expression_integer_value (context , insert -> skip_scope_index , NULL );
3295
3290
Scope * scope_for_cloned_block = NULL ;
3296
3291
if (skip_scope_index > 0 ) {
0 commit comments