lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.5k stars 162 forks source link

AST::is_a<AST::AnnAssign_t>(*x.m_body[i]) Error while implementing dataclass #722

Open Madhav2310 opened 2 years ago

Madhav2310 commented 2 years ago

I'm trying to implement decimal in the following manner:

from ltypes import i8, i16, i32, f32, f64, ccall

@dataclass
class Decimal:
    value: str

    @overload
    def __init__(self, value_: i64) -> i64:
        return self.value

    @overload
    def __init__(self, value_: i32) -> i64:
        return self.value

    @overload
    def __init__(self, value_: f32) -> f64:
        result: f64
        result = self.value
        return result

    @overload
    def __init__(self, value_: f64) -> f64:
        return float(self.value)

I'm getting the following error:

Internal Compiler Error: Unhandled exception
Traceback (most recent call last):
  Binary file "/home/madhav/lpython/src/bin/lpython", in _start()
  Binary file "/lib/x86_64-linux-gnu/libc.so.6", in __libc_start_main()
  File "/home/madhav/lpython/src/bin/lpython.cpp", line 842, in ??
    return emit_asr(arg_file, runtime_library_dir,
  File "/home/madhav/lpython/src/bin/lpython.cpp", line 169, in ??
    compiler_options.disable_main, compiler_options.symtab_only, infile);
  File "/home/madhav/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 3753, in LFortran::LPython::python_ast_to_asr(Allocator&, LFortran::LPython::AST::ast_t&, LFortran::diag::Diagnostics&, bool, bool, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
    ast_overload, parent_dir);
  File "/home/madhav/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 2363, in LFortran::LPython::symbol_table_visitor(Allocator&, LFortran::LPython::AST::Module_t const&, LFortran::diag::Diagnostics&, bool, std::map<int, LFortran::ASR::symbol_t*, std::less<int>, std::allocator<std::pair<int const, LFortran::ASR::symbol_t*> > >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
    v.visit_Module(ast);
  File "/home/madhav/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 2104, in LFortran::LPython::SymbolTableVisitor::visit_Module(LFortran::LPython::AST::Module_t const&)
    visit_stmt(*x.m_body[i]);
  File "/home/madhav/lpython/src/lpython/python_ast.h", line 1862, in LFortran::LPython::AST::BaseVisitor<LFortran::LPython::SymbolTableVisitor>::visit_stmt(LFortran::LPython::AST::stmt_t const&)
    void visit_stmt(const stmt_t &b) { visit_stmt_t(b, self()); }
  File "/home/madhav/lpython/src/lpython/python_ast.h", line 1733, in ??
    case stmtType::ClassDef: { v.visit_ClassDef((const ClassDef_t &)x); return; }
AssertFailed: AST::is_a<AST::AnnAssign_t>(*x.m_body[i])
Madhav2310 commented 2 years ago

cc: @certik @czgdp1807 @namannimmo10

Madhav2310 commented 2 years ago

@Smit-create

certik commented 2 years ago

@Madhav2310 yes, there are quite a few things we need to implement to get this working:

So just isolate each problem into a minimal reproducible example and let's fix that, one after another, until everything works.