Skip to content

Optional args fixed #2848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ RUN(NAME test_statistics_01 LABELS cpython llvm llvm_jit NOFAST)
RUN(NAME test_attributes LABELS cpython llvm llvm_jit)
# RUN(NAME test_str_attributes LABELS cpython llvm llvm_jit c)
RUN(NAME kwargs_01 LABELS cpython llvm llvm_jit NOFAST) # renable c
# RUN(NAME def_func_01 LABELS cpython llvm llvm_jit c)
RUN(NAME def_func_01 LABELS cpython llvm llvm_jit) # renable c

RUN(NAME func_inline_01 LABELS llvm llvm_jit c wasm)
RUN(NAME func_inline_02 LABELS cpython llvm llvm_jit c)
Expand Down
2 changes: 1 addition & 1 deletion libasr
Submodule libasr updated 173 files
7 changes: 4 additions & 3 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ class CommonVisitor : public AST::BaseVisitor<StructType> {
size_t missed_args_count =0;
for (size_t def_arg = args.size(); def_arg < func->n_args; def_arg++){
ASR::Variable_t* var = ASRUtils::EXPR2VAR(func->m_args[def_arg]);
if(var->m_symbolic_value == nullptr) {
if(var->m_presence != ASR::presenceType::Optional) {
missed_args_names+= "'" + std::string(var->m_name) + "' and ";
missed_args_count++;
} else {
Expand Down Expand Up @@ -4570,7 +4570,8 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
std::string arg_s = arg;
ASR::expr_t *value = nullptr;
ASR::expr_t *init_expr = nullptr;
if (i >= default_arg_index_start){
bool is_optional_arg = i >= default_arg_index_start;
if (is_optional_arg){
size_t default_arg_index = i - default_arg_index_start;
this->visit_expr(*(x.m_args.m_defaults[default_arg_index]));
init_expr = ASRUtils::EXPR(tmp);
Expand All @@ -4593,7 +4594,7 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
}
ASR::accessType s_access = ASR::accessType::Public;
ASR::presenceType s_presence = ASR::presenceType::Required;
if (i >= default_arg_index_start){
if (is_optional_arg){
s_presence = ASR::presenceType::Optional;
}
bool value_attr = false;
Expand Down
Loading