diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index bcabdd6e57..0ce3958739 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -591,6 +591,7 @@ RUN(NAME structs_27 LABELS cpython llvm c) RUN(NAME structs_28 LABELS cpython llvm c) RUN(NAME structs_29 LABELS cpython llvm) RUN(NAME structs_30 LABELS cpython llvm c) +RUN(NAME structs_31 LABELS cpython llvm c) RUN(NAME symbolics_01 LABELS cpython_sym c_sym) RUN(NAME symbolics_02 LABELS cpython_sym c_sym) diff --git a/integration_tests/structs_31.py b/integration_tests/structs_31.py new file mode 100644 index 0000000000..172c6e6408 --- /dev/null +++ b/integration_tests/structs_31.py @@ -0,0 +1,22 @@ +from lpython import packed, dataclass, i32, InOut + +@packed +@dataclass +class inner_struct: + a: i32 + +@packed +@dataclass +class outer_struct: + b: inner_struct = inner_struct(0) + +def update_my_inner_struct(my_inner_struct: InOut[inner_struct]) -> None: + my_inner_struct.a = 99999 + +def main() -> None: + my_outer_struct: outer_struct = outer_struct() + + update_my_inner_struct(my_outer_struct.b) + assert my_outer_struct.b.a == 99999 + +main() diff --git a/src/libasr/codegen/asr_to_c_cpp.h b/src/libasr/codegen/asr_to_c_cpp.h index e9610667f4..493227468d 100644 --- a/src/libasr/codegen/asr_to_c_cpp.h +++ b/src/libasr/codegen/asr_to_c_cpp.h @@ -2618,7 +2618,7 @@ PyMODINIT_FUNC PyInit_lpython_module_)" + fn_name + R"((void) { } } else { self().visit_expr(*x.m_args[i].m_value); - if( ASR::is_a(*x.m_args[i].m_value) && + if( ASR::is_a(*x.m_args[i].m_value) || ASR::is_a(*ASRUtils::expr_type(x.m_args[i].m_value)) ) { out += "&" + src; } else {