Skip to content

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

Merged
merged 4 commits into from
Oct 31, 2022

Conversation

Smit-create
Copy link
Collaborator

Fixes #1242

@Smit-create Smit-create added bug Something isn't working asr ASR related changes labels Oct 30, 2022
@Smit-create Smit-create added the ready for review PRs that are ready for review label Oct 30, 2022
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);
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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 the current_scope.

Please test this. Try using math.pi twice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@Smit-create Smit-create merged commit b2b74ca into lcompilers:main Oct 31, 2022
@Smit-create Smit-create deleted the i-1242 branch October 31, 2022 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
asr ASR related changes bug Something isn't working ready for review PRs that are ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ASR: [BUG] Error while using dot to access module variable
2 participants