Skip to content

Commit 9ab24f5

Browse files
authored
Merge pull request #2063 from Shaikh-Ubaid/fix_struct_pass_c
Fix struct pass c
2 parents 768e809 + 723e639 commit 9ab24f5

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ RUN(NAME structs_27 LABELS cpython llvm c)
591591
RUN(NAME structs_28 LABELS cpython llvm c)
592592
RUN(NAME structs_29 LABELS cpython llvm)
593593
RUN(NAME structs_30 LABELS cpython llvm c)
594+
RUN(NAME structs_31 LABELS cpython llvm c)
594595

595596
RUN(NAME symbolics_01 LABELS cpython_sym c_sym)
596597
RUN(NAME symbolics_02 LABELS cpython_sym c_sym)

integration_tests/structs_31.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from lpython import packed, dataclass, i32, InOut
2+
3+
@packed
4+
@dataclass
5+
class inner_struct:
6+
a: i32
7+
8+
@packed
9+
@dataclass
10+
class outer_struct:
11+
b: inner_struct = inner_struct(0)
12+
13+
def update_my_inner_struct(my_inner_struct: InOut[inner_struct]) -> None:
14+
my_inner_struct.a = 99999
15+
16+
def main() -> None:
17+
my_outer_struct: outer_struct = outer_struct()
18+
19+
update_my_inner_struct(my_outer_struct.b)
20+
assert my_outer_struct.b.a == 99999
21+
22+
main()

src/libasr/codegen/asr_to_c_cpp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2618,7 +2618,7 @@ PyMODINIT_FUNC PyInit_lpython_module_)" + fn_name + R"((void) {
26182618
}
26192619
} else {
26202620
self().visit_expr(*x.m_args[i].m_value);
2621-
if( ASR::is_a<ASR::ArrayItem_t>(*x.m_args[i].m_value) &&
2621+
if( ASR::is_a<ASR::ArrayItem_t>(*x.m_args[i].m_value) ||
26222622
ASR::is_a<ASR::Struct_t>(*ASRUtils::expr_type(x.m_args[i].m_value)) ) {
26232623
out += "&" + src;
26242624
} else {

0 commit comments

Comments
 (0)