Skip to content

Commit 42ff991

Browse files
committed
Allow passing StructInstanceMember to a python function
1 parent ce4612d commit 42ff991

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ RUN(NAME structs_07 LABELS llvm c
312312
RUN(NAME structs_08 LABELS cpython llvm c)
313313
RUN(NAME structs_09 LABELS cpython llvm c)
314314
RUN(NAME structs_10 LABELS cpython llvm c)
315+
RUN(NAME structs_12 LABELS cpython llvm c)
315316
RUN(NAME sizeof_01 LABELS llvm c
316317
EXTRAFILES sizeof_01b.c)
317318
RUN(NAME enum_01 LABELS cpython llvm c)

integration_tests/structs_12.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from ltypes import i32, i16, dataclass
2+
3+
@dataclass
4+
class A:
5+
x: i32
6+
y: i16
7+
8+
def add_A_members(Ax: i32, Ay: i16) -> i32:
9+
return Ax + i32(Ay)
10+
11+
def test_A_member_passing():
12+
a: A = A(0, i16(1))
13+
sum_A_members: i32 = add_A_members(a.x, a.y)
14+
print(sum_A_members)
15+
assert sum_A_members == 1
16+
17+
test_A_member_passing()

src/libasr/codegen/asr_to_llvm.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5968,7 +5968,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
59685968
builder0.SetInsertPoint(&entry_block, entry_block.getFirstInsertionPt());
59695969
llvm::AllocaInst *target = builder0.CreateAlloca(
59705970
target_type, nullptr, "call_arg_value");
5971-
if( ASR::is_a<ASR::ArrayItem_t>(*x.m_args[i].m_value) ) {
5971+
if( ASR::is_a<ASR::ArrayItem_t>(*x.m_args[i].m_value) ||
5972+
ASR::is_a<ASR::StructInstanceMember_t>(*x.m_args[i].m_value) ) {
59725973
value = CreateLoad(value);
59735974
}
59745975
if( ASR::is_a<ASR::Tuple_t>(*arg_type) ||

0 commit comments

Comments
 (0)