Skip to content
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

Returning empty list not supported #1841

Closed
Shaikh-Ubaid opened this issue May 20, 2023 · 0 comments · Fixed by #1842
Closed

Returning empty list not supported #1841

Shaikh-Ubaid opened this issue May 20, 2023 · 0 comments · Fixed by #1842

Comments

@Shaikh-Ubaid
Copy link
Collaborator

Shaikh-Ubaid commented May 20, 2023

$ cat examples/expr2.py 
from lpython import i32

def return_empty_list_of_integers() -> list[i32]:
    return []

def main0():
    x: list[i32] = return_empty_list_of_integers()
    print(len(x))

    assert len(x) == 0

main0()
$ python examples/expr2.py
0
$ lpython examples/expr2.py
Internal Compiler Error: Unhandled exception
Traceback (most recent call last):
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/bin/lpython.cpp", line 1822
    err = compile_python_to_object_file(arg_file, tmp_o, runtime_library_dir,
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/bin/lpython.cpp", line 783
    r1 = LCompilers::LPython::python_ast_to_asr(al, lm, *ast, diagnostics, compiler_options,
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 7274
    #endif
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 7227
    {
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 4405
    visit_stmt(*x.m_body[i]);
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/python_ast.h", line 1883
    void visit_stmt(const stmt_t &b) { visit_stmt_t(b, self()); }
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/python_ast.h", line 1751
    case stmtType::FunctionDef: { v.visit_FunctionDef((const FunctionDef_t &)x); return; }
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 4514
    handle_fn(x, *f);
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 4494
    transform_stmts(body, x.n_body, x.m_body);
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 4365
    this->visit_stmt(*m_body[i]);
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/python_ast.h", line 1883
    void visit_stmt(const stmt_t &b) { visit_stmt_t(b, self()); }
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/python_ast.h", line 1753
    case stmtType::ClassDef: { v.visit_ClassDef((const ClassDef_t &)x); return; }
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 6033
    ASR::expr_t *target = ASRUtils::EXPR(return_var_ref);
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/libasr/asr_utils.h", line 34
    return ASR::down_cast<ASR::expr_t>(f);
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/libasr/asr.h", line 40
    LCOMPILERS_ASSERT(f != nullptr);
AssertFailed: f != nullptr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant