@@ -2249,15 +2249,15 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
2249
2249
ASR::symbol_t * v_sym = ASR::down_cast<ASR::symbol_t >(v);
2250
2250
ASR::Variable_t* v_variable = ASR::down_cast<ASR::Variable_t>(v_sym);
2251
2251
2252
- if ( init_expr && (current_body || ASR::is_a<ASR::List_t>(*type)) &&
2253
- ( is_runtime_expression || !is_variable_const) ) {
2252
+ if ( init_expr && (current_body || ASR::is_a<ASR::List_t>(*type) ||
2253
+ is_runtime_expression) && !is_variable_const) {
2254
2254
ASR::expr_t * v_expr = ASRUtils::EXPR (ASR::make_Var_t (al, loc, v_sym));
2255
2255
cast_helper (v_expr, init_expr, true );
2256
2256
ASR::asr_t * assign = ASR::make_Assignment_t (al, loc, v_expr,
2257
2257
init_expr, nullptr );
2258
2258
if (current_body) {
2259
2259
current_body->push_back (al, ASRUtils::STMT (assign));
2260
- } else if (ASR::is_a<ASR::List_t>(*type)) {
2260
+ } else if (ASR::is_a<ASR::List_t>(*type) || is_runtime_expression ) {
2261
2261
global_init.push_back (al, assign);
2262
2262
}
2263
2263
@@ -3983,10 +3983,23 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
3983
3983
// Erase the function in TranslationUnit
3984
3984
unit->m_global_scope ->erase_symbol (func_name);
3985
3985
}
3986
+ global_init.p = nullptr ;
3987
+ global_init.n = 0 ;
3988
+ }
3989
+
3990
+ if (global_init.n > 0 ) {
3991
+ // copy all the item's from `items` (global_statements)
3992
+ // into `global_init`
3993
+ for (auto &i: items) {
3994
+ global_init.push_back (al, i);
3995
+ }
3996
+ unit->m_items = global_init.p ;
3997
+ unit->n_items = global_init.size ();
3998
+ } else {
3999
+ unit->m_items = items.p ;
4000
+ unit->n_items = items.size ();
3986
4001
}
3987
4002
3988
- unit->m_items = items.p ;
3989
- unit->n_items = items.size ();
3990
4003
if (items.n > 0 && main_module_sym) {
3991
4004
std::string func_name = " global_statements" ;
3992
4005
// Wrap all the global statements into a Function
0 commit comments