Skip to content
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

fix: check if external symbol before checking from same scope. #2434

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@ RUN(NAME structs_32 LABELS cpython llvm c)
RUN(NAME structs_33 LABELS cpython llvm c)
RUN(NAME structs_34 LABELS cpython llvm c)
RUN(NAME structs_35 LABELS cpython llvm)
RUN(NAME structs_36 LABELS cpython llvm)
RUN(NAME structs_37 LABELS cpython llvm)

RUN(NAME symbolics_01 LABELS cpython_sym c_sym llvm_sym NOFAST)
RUN(NAME symbolics_02 LABELS cpython_sym c_sym llvm_sym NOFAST)
Expand Down
10 changes: 10 additions & 0 deletions integration_tests/structs_36.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from lpython import dataclass

@dataclass
class Transaction:
date: str
name: str

@dataclass
class Transactions:
transactions: list[Transaction]
4 changes: 4 additions & 0 deletions integration_tests/structs_37.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from structs_36 import Transactions, Transaction

transactions: list[Transaction] = []
asr: Transactions = Transactions(transactions=transactions)
9 changes: 9 additions & 0 deletions src/libasr/asr_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,15 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor>
if( ASRUtils::get_asr_owner(x.m_derived_type) ) {
symbol_owner = ASRUtils::symbol_name(ASRUtils::get_asr_owner(x.m_derived_type));
}

// Resolve the symbol in the current symbol table.
ASR::symbol_t* symbol = current_symtab->resolve_symbol(ASRUtils::symbol_name(x.m_derived_type));

// If the symbol is an ExternalSymbol, then omit the check.
if (ASR::is_a<ASR::ExternalSymbol_t>(*symbol)) {
return;
}
Comment on lines +1097 to +1100
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this change is not correct --- I think the ASR is incorrect if the ExternalSymbol is not present in the current scope. So there is a bug in the way we construct the ASR that we need to fix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The symbol is there in the current_symtab imported as ExternalSymbol. But, x.m_derived_type points to actual definition of the class which is inside another module, that is why symtab_in_scope fails. I think ASR is correct as the External Symbol is there in the current scope.

Copy link
Contributor

Choose a reason for hiding this comment

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

The proper fix is described at lfortran/lfortran#2957.


require(symtab_in_scope(current_symtab, x.m_derived_type),
"Struct::m_derived_type '" +
std::string(ASRUtils::symbol_name(x.m_derived_type)) +
Expand Down
Loading