From 1f5f33cc802de330f1a7516df862c53d12f60c49 Mon Sep 17 00:00:00 2001 From: arteevraina Date: Tue, 28 Nov 2023 11:44:52 +0530 Subject: [PATCH 1/4] fix: do not check for same scope when class is imported from different module --- src/libasr/asr_verify.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libasr/asr_verify.cpp b/src/libasr/asr_verify.cpp index 7f6dc8484b..f06d91101a 100644 --- a/src/libasr/asr_verify.cpp +++ b/src/libasr/asr_verify.cpp @@ -1090,6 +1090,10 @@ class VerifyVisitor : public BaseWalkVisitor if( ASRUtils::get_asr_owner(x.m_derived_type) ) { symbol_owner = ASRUtils::symbol_name(ASRUtils::get_asr_owner(x.m_derived_type)); } + // Check if x.m_derived_type is imported from another module as an external symbol. + if( !ASR::is_a(*x.m_derived_type) ) { + return; + } require(symtab_in_scope(current_symtab, x.m_derived_type), "Struct::m_derived_type '" + std::string(ASRUtils::symbol_name(x.m_derived_type)) + From ccad3ff07b24fcce9a9c8ade78dc1903db9987a8 Mon Sep 17 00:00:00 2001 From: arteevraina Date: Tue, 28 Nov 2023 12:42:44 +0530 Subject: [PATCH 2/4] fix: resolve the symbol and omit check if external symbol --- src/libasr/asr_verify.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libasr/asr_verify.cpp b/src/libasr/asr_verify.cpp index f06d91101a..007d6571ed 100644 --- a/src/libasr/asr_verify.cpp +++ b/src/libasr/asr_verify.cpp @@ -1090,10 +1090,15 @@ class VerifyVisitor : public BaseWalkVisitor if( ASRUtils::get_asr_owner(x.m_derived_type) ) { symbol_owner = ASRUtils::symbol_name(ASRUtils::get_asr_owner(x.m_derived_type)); } - // Check if x.m_derived_type is imported from another module as an external symbol. - if( !ASR::is_a(*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(*symbol)) { return; } + require(symtab_in_scope(current_symtab, x.m_derived_type), "Struct::m_derived_type '" + std::string(ASRUtils::symbol_name(x.m_derived_type)) + From 6ef9500b67162d35d2d2f7361d5a31e8f5f5f8ce Mon Sep 17 00:00:00 2001 From: arteevraina Date: Wed, 29 Nov 2023 11:43:28 +0530 Subject: [PATCH 3/4] tests: added test for imported classes usage --- integration_tests/CMakeLists.txt | 3 +++ integration_tests/transaction_01.py | 10 ++++++++++ integration_tests/transaction_02.py | 4 ++++ 3 files changed, 17 insertions(+) create mode 100644 integration_tests/transaction_01.py create mode 100644 integration_tests/transaction_02.py diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 3540040ea6..95694d3fe8 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -798,6 +798,9 @@ RUN(NAME callback_03 LABELS cpython llvm c) RUN(NAME lambda_01 LABELS cpython llvm) +RUN(NAME transaction_01 LABELS cpython llvm c) +RUN(NAME transaction_02 LABELS cpython llvm c) + # callback_04 is to test emulation. So just run with cpython RUN(NAME callback_04 IMPORT_PATH .. LABELS cpython) diff --git a/integration_tests/transaction_01.py b/integration_tests/transaction_01.py new file mode 100644 index 0000000000..1f6ee9a26f --- /dev/null +++ b/integration_tests/transaction_01.py @@ -0,0 +1,10 @@ +from lpython import dataclass + +@dataclass +class Transaction: + date: str + name: str + +@dataclass +class Transactions: + transactions: list[Transaction] \ No newline at end of file diff --git a/integration_tests/transaction_02.py b/integration_tests/transaction_02.py new file mode 100644 index 0000000000..19dc82aba9 --- /dev/null +++ b/integration_tests/transaction_02.py @@ -0,0 +1,4 @@ +from transaction_01 import Transactions, Transaction + +transactions: list[Transaction] = [] +asr: Transactions = Transactions(transactions=transactions) \ No newline at end of file From 56b964d20aa92f56499b5db0218b54db3fe5938c Mon Sep 17 00:00:00 2001 From: arteevraina Date: Wed, 29 Nov 2023 20:54:13 +0530 Subject: [PATCH 4/4] tests: update file names --- integration_tests/CMakeLists.txt | 5 ++--- integration_tests/{transaction_01.py => structs_36.py} | 0 integration_tests/{transaction_02.py => structs_37.py} | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) rename integration_tests/{transaction_01.py => structs_36.py} (100%) rename integration_tests/{transaction_02.py => structs_37.py} (64%) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 95694d3fe8..8765026195 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -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) @@ -798,9 +800,6 @@ RUN(NAME callback_03 LABELS cpython llvm c) RUN(NAME lambda_01 LABELS cpython llvm) -RUN(NAME transaction_01 LABELS cpython llvm c) -RUN(NAME transaction_02 LABELS cpython llvm c) - # callback_04 is to test emulation. So just run with cpython RUN(NAME callback_04 IMPORT_PATH .. LABELS cpython) diff --git a/integration_tests/transaction_01.py b/integration_tests/structs_36.py similarity index 100% rename from integration_tests/transaction_01.py rename to integration_tests/structs_36.py diff --git a/integration_tests/transaction_02.py b/integration_tests/structs_37.py similarity index 64% rename from integration_tests/transaction_02.py rename to integration_tests/structs_37.py index 19dc82aba9..83d1953d06 100644 --- a/integration_tests/transaction_02.py +++ b/integration_tests/structs_37.py @@ -1,4 +1,4 @@ -from transaction_01 import Transactions, Transaction +from structs_36 import Transactions, Transaction transactions: list[Transaction] = [] asr: Transactions = Transactions(transactions=transactions) \ No newline at end of file