Skip to content

Commit 5a24e0a

Browse files
committed
Only transform local variables for their values
Previously we were transforming arguments also, and if they are intent(in), it becomes problematic. To solve optional arguments, we should assign their values at the call site, like LPython does. Towards lcompilers/lpython#2851.
1 parent 20d5b2a commit 5a24e0a

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/libasr/pass/array_struct_temporary.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,12 +2209,15 @@ class TransformVariableInitialiser:
22092209
}
22102210

22112211
exprs_with_target[value] = std::make_pair(target, targetType::OriginalTarget);
2212-
if (ASRUtils::is_pointer(x.m_type)) {
2213-
result_vec.push_back(al, ASRUtils::STMT(ASR::make_Associate_t(
2214-
al, loc, target, value)));
2215-
} else {
2216-
result_vec.push_back(al, ASRUtils::STMT(make_Assignment_t_util(
2217-
al, loc, target, value, nullptr, exprs_with_target)));
2212+
// Transform local variables, but not dummy arguments
2213+
if (xx.m_intent == ASR::intentType::Local) {
2214+
if (ASRUtils::is_pointer(x.m_type)) {
2215+
result_vec.push_back(al, ASRUtils::STMT(ASR::make_Associate_t(
2216+
al, loc, target, value)));
2217+
} else {
2218+
result_vec.push_back(al, ASRUtils::STMT(make_Assignment_t_util(
2219+
al, loc, target, value, nullptr, exprs_with_target)));
2220+
}
22182221
}
22192222
xx.m_symbolic_value = nullptr;
22202223
xx.m_value = nullptr;

0 commit comments

Comments
 (0)