Skip to content

Commit e2bd8ee

Browse files
authored
Merge pull request #1227 from ansharlubis/fix-generic-instantiation
Fixed issues on template instantiation
2 parents a112710 + 18b9375 commit e2bd8ee

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/libasr/pass/instantiate_template.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace LFortran {
1010
class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstantiator>
1111
{
1212
public:
13+
SymbolTable *func_scope;
1314
SymbolTable *current_scope;
1415
std::map<std::string, ASR::ttype_t*> subs;
1516
std::map<std::string, ASR::symbol_t*> rt_subs;
@@ -18,18 +19,17 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti
1819
std::set<std::string> dependencies;
1920

2021
FunctionInstantiator(Allocator &al, std::map<std::string, ASR::ttype_t*> subs,
21-
std::map<std::string, ASR::symbol_t*> rt_subs, SymbolTable *current_scope,
22+
std::map<std::string, ASR::symbol_t*> rt_subs, SymbolTable *func_scope,
2223
std::string new_func_name):
2324
BaseExprStmtDuplicator(al),
24-
current_scope{current_scope},
25+
func_scope{func_scope},
2526
subs{subs},
2627
rt_subs{rt_subs},
2728
new_func_name{new_func_name}
2829
{}
2930

3031
ASR::asr_t* instantiate_Function(ASR::Function_t *x) {
3132
dependencies.clear();
32-
SymbolTable *parent_scope = current_scope;
3333
current_scope = al.make_new<SymbolTable>(x->m_symtab->parent);
3434

3535
Vec<ASR::expr_t*> args;
@@ -135,7 +135,6 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti
135135

136136
ASR::symbol_t *t = ASR::down_cast<ASR::symbol_t>(result);
137137
x->m_symtab->parent->add_symbol(new_func_name, t);
138-
current_scope = parent_scope;
139138

140139
return result;
141140
}
@@ -223,7 +222,7 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti
223222

224223
ASR::asr_t* duplicate_FunctionCall(ASR::FunctionCall_t *x) {
225224
std::string sym_name = ASRUtils::symbol_name(x->m_name);
226-
ASR::symbol_t *name = current_scope->get_symbol(sym_name);
225+
ASR::symbol_t *name = func_scope->get_symbol(sym_name);
227226
Vec<ASR::call_arg_t> args;
228227
args.reserve(al, x->n_args);
229228
for (size_t i=0; i<x->n_args; i++) {

0 commit comments

Comments
 (0)