Skip to content

Commit

Permalink
Add comparing Function types
Browse files Browse the repository at this point in the history
  • Loading branch information
Smit-create committed Apr 24, 2023
1 parent f96fcf1 commit 1d5a7e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/libasr/asr_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,27 @@ inline bool check_equal_type(ASR::ttype_t* x, ASR::ttype_t* y) {
std::string left_param = left_tp->m_param;
std::string right_param = right_tp->m_param;
return left_param.compare(right_param) == 0;
} else if (ASR::is_a<ASR::FunctionType_t>(*x) && ASR::is_a<ASR::FunctionType_t>(*y)) {
ASR::FunctionType_t* left_ft = ASR::down_cast<ASR::FunctionType_t>(x);
ASR::FunctionType_t* right_ft = ASR::down_cast<ASR::FunctionType_t>(y);
if (left_ft->n_arg_types != right_ft->n_arg_types) {
return false;
}
bool result;
for (size_t i=0; i<left_ft->n_arg_types; i++) {
result = check_equal_type(left_ft->m_arg_types[i],
right_ft->m_arg_types[i]);
if (!result) return false;
}
if (left_ft->m_return_var_type == nullptr &&
right_ft->m_return_var_type == nullptr) {
return true;
} else if (left_ft->m_return_var_type != nullptr &&
right_ft->m_return_var_type != nullptr) {
return check_equal_type(left_ft->m_return_var_type,
right_ft->m_return_var_type);
}
return false;
}

return types_equal(x, y);
Expand Down
4 changes: 0 additions & 4 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,10 +882,6 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
cast_helper(m_args[i], c_arg.m_value, true);
ASR::ttype_t* left_type = ASRUtils::expr_type(m_args[i]);
ASR::ttype_t* right_type = ASRUtils::expr_type(c_arg.m_value);
if (ASR::is_a<ASR::FunctionType_t>(*left_type) ) {
// TODO: add FunctionType in check_equal_type
continue;
}
if( check_type_equality && !ASRUtils::check_equal_type(left_type, right_type) ) {
std::string ltype = ASRUtils::type_to_str_python(left_type);
std::string rtype = ASRUtils::type_to_str_python(right_type);
Expand Down

0 comments on commit 1d5a7e7

Please sign in to comment.