Skip to content

Allow to ignore a function result #667

@certik

Description

@certik

A CPython test added in #666:

from ltypes import i32

def g() -> i32:
    return 5

def test_fn1():
    i: i32 = g()
    g()

test_fn1()

Currently it prints in LPython:

$ lpython expr_10.py
Internal Compiler Error: Unhandled exception
Traceback (most recent call last):
  File "/Users/ondrej/repos/lpython/src/bin/lpython.cpp", line 894
    err = compile_python_to_object_file(arg_file, tmp_o, runtime_library_dir, compiler_options, time_report);
  File "/Users/ondrej/repos/lpython/src/bin/lpython.cpp", line 356
    r1 = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, true,
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 3726
    auto res2 = body_visitor(al, *ast_m, diagnostics, unit, main_module,
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 3653
    b.visit_Module(ast);
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 2385
    visit_stmt(*x.m_body[i]);
  File "/Users/ondrej/repos/lpython/src/lpython/python_ast.h", line 1862
    void visit_stmt(const stmt_t &b) { visit_stmt_t(b, self()); }
  File "/Users/ondrej/repos/lpython/src/lpython/python_ast.h", line 1731
    case stmtType::FunctionDef: { v.visit_FunctionDef((const FunctionDef_t &)x); return; }
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 2412
    handle_fn(x, *ASR::down_cast<ASR::Subroutine_t>(t));
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 2403
    transform_stmts(body, x.n_body, x.m_body);
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 2362
    if (tmp != nullptr) {
  File "/Users/ondrej/repos/lpython/src/libasr/asr_utils.h", line 27
    return ASR::down_cast<ASR::stmt_t>(f);
  File "/Users/ondrej/repos/lpython/src/libasr/asr.h", line 40
    LFORTRAN_ASSERT(is_a<T>(*f));
AssertFailed: is_a<T>(*f)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions