← 输入框|github.com|刷新
Skip to content

Bug: Assert failure in logical operation #2597

Closed

Description

@ubaidsk
% cat examples/expr2.py 
print(2.0 > 0.0 and 2.0**0.5)
% python examples/expr2.py                
1.4142135623730951
% lpython examples/expr2.py --backend llvm
Internal Compiler Error: Unhandled exception
Traceback (most recent call last):
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/bin/lpython.cpp", line 1929
    err = compile_python_to_object_file(arg_file, tmp_o, runtime_library_dir,
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/bin/lpython.cpp", line 837
    r1 = LCompilers::LPython::python_ast_to_asr(al, lm, nullptr, *ast, diagnostics, compiler_options,
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 8149
    auto res2 = body_visitor(al, lm, *ast_m, diagnostics, unit, main_module, module_name,
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 8085
    BodyVisitor b(al, lm, unit, diagnostics, main_module, module_name, ast_overload, allow_implicit_casting);
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 4732
    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 1772
    case stmtType::Nonlocal: { v.visit_Nonlocal((const Nonlocal_t &)x); return; }
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 6524
    AST::Call_t *c = AST::down_cast<AST::Call_t>(x.m_value);
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 7618
    visit_expr_list(x.m_args, x.n_args, args);
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 613
    this->visit_expr(*exprs[i]);
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/python_ast.h", line 1910
    void visit_expr(const expr_t &b) { visit_expr_t(b, self()); }
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/python_ast.h", line 1784
    case exprType::BoolOp: { v.visit_BoolOp((const BoolOp_t &)x); return; }
  File "/Users/ubaid/Desktop/OpenSource/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 3329
    LCOMPILERS_ASSERT(
AssertFailed: ASRUtils::check_equal_type(ASRUtils::expr_type(lhs), ASRUtils::expr_type(rhs))

We should rather be printing a semantic error that the types to the logical operation are not equal and also are not of type logical.

Activity

  1. ubaidsk commented on Mar 16, 2024

    @ubaidsk
    CollaboratorAuthor

    From #1506 (comment), it looks like and operation on types other than logical is valid.

    >>> 2 and 3
    3
    >>> 0 and 3
    0
    >>> True and 3
    3
    >>> False and 3
    False
    >>> -1 and 3
    3

    It returns the left side value if it is false, otherwise the right side value. So, in this current issue, we just need to fix the assert failure shared in the issue description (#2597 (comment)) above.

  2. ubaidsk commented on Mar 16, 2024

    @ubaidsk
    CollaboratorAuthor

    Another example related to this shared here #2598 (comment).

    % cat examples/expr2.py 
    print(1 or 3)
    % python examples/expr2.py          
    1
    % lpython_in_main examples/expr2.py 
    Internal Compiler Error: Unhandled exception
    Traceback (most recent call last):
      File "/Users/ubaid/Desktop/OpenSource/lpython_in_main/src/bin/lpython.cpp", line 1932
        err = compile_python_to_object_file(arg_file, tmp_o, runtime_library_dir,
      File "/Users/ubaid/Desktop/OpenSource/lpython_in_main/src/bin/lpython.cpp", line 837
        r1 = LCompilers::LPython::python_ast_to_asr(al, lm, nullptr, *ast, diagnostics, compiler_options,
      File "/Users/ubaid/Desktop/OpenSource/lpython_in_main/src/lpython/semantics/python_ast_to_asr.cpp", line 8149
        auto res2 = body_visitor(al, lm, *ast_m, diagnostics, unit, main_module, module_name,
      File "/Users/ubaid/Desktop/OpenSource/lpython_in_main/src/lpython/semantics/python_ast_to_asr.cpp", line 8085
        BodyVisitor b(al, lm, unit, diagnostics, main_module, module_name, ast_overload, allow_implicit_casting);
      File "/Users/ubaid/Desktop/OpenSource/lpython_in_main/src/lpython/semantics/python_ast_to_asr.cpp", line 4732
        visit_stmt(*x.m_body[i]);
      File "/Users/ubaid/Desktop/OpenSource/lpython_in_main/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_in_main/src/lpython/python_ast.h", line 1772
        case stmtType::Nonlocal: { v.visit_Nonlocal((const Nonlocal_t &)x); return; }
      File "/Users/ubaid/Desktop/OpenSource/lpython_in_main/src/lpython/semantics/python_ast_to_asr.cpp", line 6524
        AST::Call_t *c = AST::down_cast<AST::Call_t>(x.m_value);
      File "/Users/ubaid/Desktop/OpenSource/lpython_in_main/src/lpython/semantics/python_ast_to_asr.cpp", line 7618
        visit_expr_list(x.m_args, x.n_args, args);
      File "/Users/ubaid/Desktop/OpenSource/lpython_in_main/src/lpython/semantics/python_ast_to_asr.cpp", line 613
        this->visit_expr(*exprs[i]);
      File "/Users/ubaid/Desktop/OpenSource/lpython_in_main/src/lpython/python_ast.h", line 1910
        void visit_expr(const expr_t &b) { visit_expr_t(b, self()); }
      File "/Users/ubaid/Desktop/OpenSource/lpython_in_main/src/lpython/python_ast.h", line 1784
        case exprType::BoolOp: { v.visit_BoolOp((const BoolOp_t &)x); return; }
      File "/Users/ubaid/Desktop/OpenSource/lpython_in_main/src/lpython/semantics/python_ast_to_asr.cpp", line 3336
        LCOMPILERS_ASSERT(ASR::is_a<ASR::Logical_t>(*dest_type));
    AssertFailed: ASR::is_a<ASR::Logical_t>(*dest_type)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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