Open rebcabin opened 1 year ago
Looks like we DO have field
and default_factory
! GREAT!
can you assign this issue to me?
I need a little help here to work with. I went a little through the python_ast_to_asr.cpp
file and I am think I need to handle the error here instead of throwing. I am not sure about this please confirm
void visit_List(const AST::List_t &x) {
Vec<ASR::expr_t*> list;
list.reserve(al, x.n_elts + 1);
ASR::ttype_t *type = nullptr;
ASR::expr_t *expr = nullptr;
if( x.n_elts > 0 ) {
this->visit_expr(*x.m_elts[0]);
expr = ASRUtils::EXPR(tmp);
type = ASRUtils::expr_type(expr);
list.push_back(al, expr);
for (size_t i = 1; i < x.n_elts; i++) {
this->visit_expr(*x.m_elts[i]);
expr = ASRUtils::EXPR(tmp);
if (!ASRUtils::check_equal_type(ASRUtils::expr_type(expr), type)) {
// Handle the error instead of throwing ?
throw SemanticError("All List elements must be of the same type for now",
x.base.base.loc);
}
list.push_back(al, expr);
}
} else {
if( assign_asr_target == nullptr ) {
tmp = nullptr;
return ;
}
type = ASRUtils::get_contained_type(
ASRUtils::type_get_past_const(ASRUtils::expr_type(assign_asr_target)));
}
ASR::ttype_t* list_type = ASRUtils::TYPE(ASR::make_List_t(al, x.base.base.loc, type));
tmp = ASR::make_ListConstant_t(al, x.base.base.loc, list.p,
list.size(), list_type);
}
Also how can I compile lpython code?
I want to reproduce the output for this code locally
from lpython import dataclass, i32
@dataclass
class foo:
bar : list[i32] = [] ######### INCORRECT ###########
offending code:
run: