diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 8bcddab123..590da72d46 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -372,6 +372,7 @@ RUN(NAME test_list_07 LABELS cpython llvm c) RUN(NAME test_list_08 LABELS cpython llvm c) RUN(NAME test_list_09 LABELS cpython llvm c) RUN(NAME test_list_10 LABELS cpython llvm c) +RUN(NAME test_list_11 LABELS cpython llvm c) RUN(NAME test_list_section LABELS cpython llvm c) RUN(NAME test_list_count LABELS cpython llvm) RUN(NAME test_list_index LABELS cpython llvm) diff --git a/integration_tests/test_list_11.py b/integration_tests/test_list_11.py new file mode 100644 index 0000000000..f9d2b3fc48 --- /dev/null +++ b/integration_tests/test_list_11.py @@ -0,0 +1,12 @@ +from lpython import i32 + +def return_empty_list_of_tuples() -> list[i32]: + return [] + +def main0(): + x: list[i32] = return_empty_list_of_tuples() + print(len(x)) + + assert len(x) == 0 + +main0() diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index b0a0424757..6cbfa2f6d6 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -6029,15 +6029,18 @@ class BodyVisitor : public CommonVisitor { tmp = ASR::make_Return_t(al, x.base.base.loc); return; } - this->visit_expr(*x.m_value); - ASR::expr_t *value = ASRUtils::EXPR(tmp); ASR::asr_t *return_var_ref = ASR::make_Var_t(al, x.base.base.loc, return_var); ASR::expr_t *target = ASRUtils::EXPR(return_var_ref); ASR::ttype_t *target_type = ASRUtils::expr_type(target); - ASR::ttype_t *value_type = ASRUtils::expr_type(value); if( ASR::is_a(*target_type) ) { target_type = ASRUtils::get_contained_type(target_type); } + ASR::ttype_t* ann_assign_target_type_copy = ann_assign_target_type; + ann_assign_target_type = target_type; + this->visit_expr(*x.m_value); + ann_assign_target_type = ann_assign_target_type_copy; + ASR::expr_t *value = ASRUtils::EXPR(tmp); + ASR::ttype_t *value_type = ASRUtils::expr_type(value); if( ASR::is_a(*value_type) ) { value_type = ASRUtils::get_contained_type(value_type); }