@@ -395,14 +395,15 @@ ASR::Module_t* load_module(Allocator &al, SymbolTable *symtab,
395
395
396
396
ASR::symbol_t * import_from_module (Allocator &al, ASR::Module_t *m, SymbolTable *current_scope,
397
397
std::string mname, std::string cur_sym_name, std::string new_sym_name,
398
- const Location &loc) {
398
+ const Location &loc, bool skip_current_scope_check= false ) {
399
399
ASR::symbol_t *t = m->m_symtab ->resolve_symbol (cur_sym_name);
400
400
if (!t) {
401
401
throw SemanticError (" The symbol '" + cur_sym_name + " ' not found in the module '" + mname + " '" ,
402
402
loc);
403
403
}
404
- if (current_scope->get_scope ().find (cur_sym_name) != current_scope->get_scope ().end ()) {
405
- throw SemanticError (cur_sym_name + " already defined" , loc);
404
+ if (!skip_current_scope_check &&
405
+ current_scope->get_scope ().find (new_sym_name) != current_scope->get_scope ().end ()) {
406
+ throw SemanticError (new_sym_name + " already defined" , loc);
406
407
}
407
408
if (ASR::is_a<ASR::Function_t>(*t)) {
408
409
ASR::Function_t *mfn = ASR::down_cast<ASR::Function_t>(t);
@@ -4391,6 +4392,17 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
4391
4392
tmp = ASR::make_EnumValue_t (al, x.base .base .loc , enum_member_var,
4392
4393
enum_t , enum_member_variable->m_type ,
4393
4394
ASRUtils::expr_value (enum_member_variable->m_symbolic_value ));
4395
+ } else if (ASR::is_a<ASR::Module_t>(*t)) {
4396
+ ASR::Module_t *m = ASR::down_cast<ASR::Module_t>(t);
4397
+ std::string sym_name = value + " @" + x.m_attr ;
4398
+ ASR::symbol_t *sym = current_scope->resolve_symbol (sym_name);
4399
+ if (!sym) {
4400
+ sym = import_from_module (al, m, current_scope, value,
4401
+ x.m_attr , sym_name, x.base .base .loc , true );
4402
+ LFORTRAN_ASSERT (ASR::is_a<ASR::ExternalSymbol_t>(*sym));
4403
+ current_scope->add_symbol (sym_name, sym);
4404
+ }
4405
+ tmp = ASR::make_Var_t (al, x.base .base .loc , sym);
4394
4406
} else {
4395
4407
throw SemanticError (" Only Variable type is supported for now in Attribute" ,
4396
4408
x.base .base .loc );
0 commit comments