Skip to content

Commit 7d347d8

Browse files
committed
Fix to allow symbol with same name present in other module and used by dot
1 parent c375d4f commit 7d347d8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,14 @@ ASR::Module_t* load_module(Allocator &al, SymbolTable *symtab,
395395

396396
ASR::symbol_t* import_from_module(Allocator &al, ASR::Module_t *m, SymbolTable *current_scope,
397397
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) {
399399
ASR::symbol_t *t = m->m_symtab->resolve_symbol(cur_sym_name);
400400
if (!t) {
401401
throw SemanticError("The symbol '" + cur_sym_name + "' not found in the module '" + mname + "'",
402402
loc);
403403
}
404-
if (current_scope->get_scope().find(cur_sym_name) != current_scope->get_scope().end()) {
404+
if (!skip_current_scope_check &&
405+
current_scope->get_scope().find(cur_sym_name) != current_scope->get_scope().end()) {
405406
throw SemanticError(cur_sym_name + " already defined", loc);
406407
}
407408
if (ASR::is_a<ASR::Function_t>(*t)) {
@@ -4393,10 +4394,14 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
43934394
ASRUtils::expr_value(enum_member_variable->m_symbolic_value));
43944395
} else if (ASR::is_a<ASR::Module_t>(*t)) {
43954396
ASR::Module_t *m = ASR::down_cast<ASR::Module_t>(t);
4396-
ASR::symbol_t *sym = import_from_module(al, m, current_scope, value,
4397-
x.m_attr, x.m_attr, x.base.base.loc);
4398-
LFORTRAN_ASSERT(ASR::is_a<ASR::ExternalSymbol_t>(*sym));
4399-
current_scope->add_symbol(x.m_attr, sym);
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+
}
44004405
tmp = ASR::make_Var_t(al, x.base.base.loc, sym);
44014406
} else {
44024407
throw SemanticError("Only Variable type is supported for now in Attribute",

0 commit comments

Comments
 (0)