Skip to content

Commit 5880e96

Browse files
authored
Optional args (#2851)
1 parent 45e08d1 commit 5880e96

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ RUN(NAME test_statistics_01 LABELS cpython llvm llvm_jit NOFAST)
805805
RUN(NAME test_attributes LABELS cpython llvm llvm_jit)
806806
# RUN(NAME test_str_attributes LABELS cpython llvm llvm_jit c)
807807
RUN(NAME kwargs_01 LABELS cpython llvm llvm_jit NOFAST) # renable c
808-
# RUN(NAME def_func_01 LABELS cpython llvm llvm_jit c)
808+
RUN(NAME def_func_01 LABELS cpython llvm llvm_jit) # renable c
809809

810810
RUN(NAME func_inline_01 LABELS llvm llvm_jit c wasm)
811811
RUN(NAME func_inline_02 LABELS cpython llvm llvm_jit c)

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ class CommonVisitor : public AST::BaseVisitor<StructType> {
11781178
size_t missed_args_count =0;
11791179
for (size_t def_arg = args.size(); def_arg < func->n_args; def_arg++){
11801180
ASR::Variable_t* var = ASRUtils::EXPR2VAR(func->m_args[def_arg]);
1181-
if(var->m_symbolic_value == nullptr) {
1181+
if(var->m_presence != ASR::presenceType::Optional) {
11821182
missed_args_names+= "'" + std::string(var->m_name) + "' and ";
11831183
missed_args_count++;
11841184
} else {
@@ -4570,7 +4570,8 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
45704570
std::string arg_s = arg;
45714571
ASR::expr_t *value = nullptr;
45724572
ASR::expr_t *init_expr = nullptr;
4573-
if (i >= default_arg_index_start){
4573+
bool is_optional_arg = i>=default_arg_index_start;
4574+
if (is_optional_arg){
45744575
size_t default_arg_index = i - default_arg_index_start;
45754576
this->visit_expr(*(x.m_args.m_defaults[default_arg_index]));
45764577
init_expr = ASRUtils::EXPR(tmp);
@@ -4593,7 +4594,7 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
45934594
}
45944595
ASR::accessType s_access = ASR::accessType::Public;
45954596
ASR::presenceType s_presence = ASR::presenceType::Required;
4596-
if (i >= default_arg_index_start){
4597+
if (is_optional_arg){
45974598
s_presence = ASR::presenceType::Optional;
45984599
}
45994600
bool value_attr = false;

0 commit comments

Comments
 (0)