-
Notifications
You must be signed in to change notification settings - Fork 171
ASR: Allow variable access from module using dot #1243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ASR::symbol_t *sym = import_from_module(al, m, current_scope, value, | ||
x.m_attr, x.m_attr, x.base.base.loc); | ||
LFORTRAN_ASSERT(ASR::is_a<ASR::ExternalSymbol_t>(*sym)); | ||
current_scope->add_symbol(x.m_attr, sym); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if its already imported and added? We will add it to the current scope even though its already there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that here we should change the name of the symbol too. If we are already using some variable with the same name then it might be a conflict, for example:
import math
def f():
pi: f64 = 4.5030
print(math.pi, math.e)
f()
This gives an error:
semantic error: pi already defined
To tackle this, we need to change the symbol name to module_name@attr_name
.
We will add it to the current scope even though its already there?
import_from_module
ensures that the symbol is not present in the current_scope
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To tackle this, we need to change the symbol name to
module_name@attr_name
.
Correct, name mangling is needed here I think. @certik Thoughts?
import_from_module
ensures that the symbol is not present in thecurrent_scope
.
Please test this. Try using math.pi
twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Fixes #1242