@@ -3247,10 +3247,12 @@ class ReplaceWithFunctionParamVisitor: public ASR::BaseExprReplacer<ReplaceWithF
3247
3247
3248
3248
size_t n_args;
3249
3249
3250
+ SymbolTable* current_scope;
3251
+
3250
3252
public:
3251
3253
3252
3254
ReplaceWithFunctionParamVisitor (Allocator& al_, ASR::expr_t ** m_args_, size_t n_args_) :
3253
- al (al_), m_args(m_args_), n_args(n_args_) {}
3255
+ al (al_), m_args(m_args_), n_args(n_args_), current_scope( nullptr ) {}
3254
3256
3255
3257
void replace_Var (ASR::Var_t* x) {
3256
3258
size_t arg_idx = 0 ;
@@ -3268,14 +3270,16 @@ class ReplaceWithFunctionParamVisitor: public ASR::BaseExprReplacer<ReplaceWithF
3268
3270
if ( idx_found ) {
3269
3271
LCOMPILERS_ASSERT (current_expr);
3270
3272
ASR::ttype_t * t_ = replace_args_with_FunctionParam (
3271
- ASRUtils::symbol_type (x->m_v ));
3273
+ ASRUtils::symbol_type (x->m_v ), current_scope );
3272
3274
*current_expr = ASRUtils::EXPR (ASR::make_FunctionParam_t (
3273
3275
al, m_args[arg_idx]->base .loc , arg_idx,
3274
3276
t_, nullptr ));
3275
3277
}
3276
3278
}
3277
3279
3278
- ASR::ttype_t * replace_args_with_FunctionParam (ASR::ttype_t * t) {
3280
+ ASR::ttype_t * replace_args_with_FunctionParam (ASR::ttype_t * t, SymbolTable* current_scope) {
3281
+ this ->current_scope = current_scope;
3282
+
3279
3283
ASRUtils::ExprStmtDuplicator duplicator (al);
3280
3284
duplicator.allow_procedure_calls = true ;
3281
3285
@@ -3312,21 +3316,21 @@ inline ASR::asr_t* make_FunctionType_t_util(Allocator &al,
3312
3316
ASR::expr_t * a_return_var, ASR::abiType a_abi, ASR::deftypeType a_deftype,
3313
3317
char * a_bindc_name, bool a_elemental, bool a_pure, bool a_module, bool a_inline,
3314
3318
bool a_static,
3315
- ASR::symbol_t ** a_restrictions, size_t n_restrictions, bool a_is_restriction) {
3319
+ ASR::symbol_t ** a_restrictions, size_t n_restrictions, bool a_is_restriction, SymbolTable* current_scope ) {
3316
3320
Vec<ASR::ttype_t *> arg_types;
3317
3321
arg_types.reserve (al, n_args);
3318
3322
ReplaceWithFunctionParamVisitor replacer (al, a_args, n_args);
3319
3323
for ( size_t i = 0 ; i < n_args; i++ ) {
3320
3324
// We need to substitute all direct argument variable references with
3321
3325
// FunctionParam.
3322
3326
ASR::ttype_t *t = replacer.replace_args_with_FunctionParam (
3323
- expr_type (a_args[i]));
3327
+ expr_type (a_args[i]), current_scope );
3324
3328
arg_types.push_back (al, t);
3325
3329
}
3326
3330
ASR::ttype_t * return_var_type = nullptr ;
3327
3331
if ( a_return_var ) {
3328
3332
return_var_type = replacer.replace_args_with_FunctionParam (
3329
- ASRUtils::expr_type (a_return_var));
3333
+ ASRUtils::expr_type (a_return_var), current_scope );
3330
3334
}
3331
3335
3332
3336
LCOMPILERS_ASSERT (arg_types.size () == n_args);
@@ -3338,12 +3342,12 @@ inline ASR::asr_t* make_FunctionType_t_util(Allocator &al,
3338
3342
}
3339
3343
3340
3344
inline ASR::asr_t * make_FunctionType_t_util (Allocator &al, const Location &a_loc,
3341
- ASR::expr_t ** a_args, size_t n_args, ASR::expr_t * a_return_var, ASR::FunctionType_t* ft) {
3345
+ ASR::expr_t ** a_args, size_t n_args, ASR::expr_t * a_return_var, ASR::FunctionType_t* ft, SymbolTable* current_scope ) {
3342
3346
return ASRUtils::make_FunctionType_t_util (al, a_loc, a_args, n_args, a_return_var,
3343
3347
ft->m_abi , ft->m_deftype , ft->m_bindc_name , ft->m_elemental ,
3344
3348
ft->m_pure , ft->m_module , ft->m_inline , ft->m_static ,
3345
3349
ft->m_restrictions ,
3346
- ft->n_restrictions , ft->m_is_restriction );
3350
+ ft->n_restrictions , ft->m_is_restriction , current_scope );
3347
3351
}
3348
3352
3349
3353
inline ASR::asr_t * make_Function_t_util (Allocator& al, const Location& loc,
@@ -3357,7 +3361,7 @@ inline ASR::asr_t* make_Function_t_util(Allocator& al, const Location& loc,
3357
3361
ASR::ttype_t * func_type = ASRUtils::TYPE (ASRUtils::make_FunctionType_t_util (
3358
3362
al, loc, a_args, n_args, m_return_var, m_abi, m_deftype, m_bindc_name,
3359
3363
m_elemental, m_pure, m_module, m_inline, m_static,
3360
- m_restrictions, n_restrictions, m_is_restriction));
3364
+ m_restrictions, n_restrictions, m_is_restriction, m_symtab ));
3361
3365
return ASR::make_Function_t (
3362
3366
al, loc, m_symtab, m_name, func_type, m_dependencies, n_dependencies,
3363
3367
a_args, n_args, m_body, n_body, m_return_var, m_access, m_deterministic,
0 commit comments