@@ -5255,24 +5255,26 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
52555255 if ( sym && ASR::is_a<ASR::Variable_t>(*sym) ) {
52565256 ASR::Variable_t* var = ASR::down_cast<ASR::Variable_t>(sym);
52575257 if ( ASR::is_a<ASR::StructType_t>(*(var->m_type )) &&
5258- !ASR::down_cast<ASR::StructType_t>((var->m_type ))->m_is_cstruct &&
5259- ASR::is_a<ASR::StructConstructor_t>(*init_expr) ) {
5260- AST::Call_t* call = AST::down_cast<AST::Call_t>(x.m_value );
5261- if ( call->n_keywords >0 ) {
5262- throw SemanticError (" Kwargs not implemented yet" , x.base .base .loc );
5263- }
5264- Vec<ASR::call_arg_t > args;
5265- args.reserve (al, call->n_args + 1 );
5266- ASR::call_arg_t self_arg;
5267- self_arg.loc = x.base .base .loc ;
5268- self_arg.m_value = ASRUtils::EXPR (ASR::make_Var_t (al, x.base .base .loc , sym));
5269- args.push_back (al, self_arg);
5270- visit_expr_list (call->m_args , call->n_args , args);
5271- ASR::symbol_t * der = ASR::down_cast<ASR::StructType_t>((var->m_type ))->m_derived_type ;
5272- std::string call_name = " __init__" ;
5273- ASR::symbol_t * call_sym = get_struct_member (der, call_name, x.base .base .loc );
5274- tmp = make_call_helper (al, call_sym, current_scope, args, call_name, x.base .base .loc );
5258+ !ASR::down_cast<ASR::StructType_t>((var->m_type ))->m_is_cstruct ) {
5259+ if ( !ASR::is_a<ASR::StructConstructor_t>(*init_expr) ) {
5260+ throw SemanticError (" Only Class constructor is allowed in the object assignment for now" , x.base .base .loc );
5261+ }
5262+ AST::Call_t* call = AST::down_cast<AST::Call_t>(x.m_value );
5263+ if ( call->n_keywords >0 ) {
5264+ throw SemanticError (" Kwargs not implemented yet" , x.base .base .loc );
52755265 }
5266+ Vec<ASR::call_arg_t > args;
5267+ args.reserve (al, call->n_args + 1 );
5268+ ASR::call_arg_t self_arg;
5269+ self_arg.loc = x.base .base .loc ;
5270+ self_arg.m_value = ASRUtils::EXPR (ASR::make_Var_t (al, x.base .base .loc , sym));
5271+ args.push_back (al, self_arg);
5272+ visit_expr_list (call->m_args , call->n_args , args);
5273+ ASR::symbol_t * der = ASR::down_cast<ASR::StructType_t>((var->m_type ))->m_derived_type ;
5274+ std::string call_name = " __init__" ;
5275+ ASR::symbol_t * call_sym = get_struct_member (der, call_name, x.base .base .loc );
5276+ tmp = make_call_helper (al, call_sym, current_scope, args, call_name, x.base .base .loc );
5277+ }
52765278 }
52775279 }
52785280
@@ -5539,11 +5541,18 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
55395541 if (target->type == ASR::exprType::Var) {
55405542 ASR::Var_t *var = ASR::down_cast<ASR::Var_t>(target);
55415543 ASR::symbol_t *sym = var->m_v ;
5544+ ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(sym);
55425545 if (do_loop_variables.size () > 0 && std::find (do_loop_variables.begin (), do_loop_variables.end (), sym) != do_loop_variables.end ()) {
5543- ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(sym);
55445546 std::string var_name = std::string (v->m_name );
55455547 throw SemanticError (" Assignment to loop variable `" + std::string (to_lower (var_name)) +" ` is not allowed" , target->base .loc );
55465548 }
5549+ if ( ASR::is_a<ASR::StructType_t>(*(v->m_type )) &&
5550+ !ASR::down_cast<ASR::StructType_t>((v->m_type ))->m_is_cstruct &&
5551+ !(tmp_value->type == ASR::exprType::StructConstructor) ) {
5552+ ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(sym);
5553+ std::string var_name = std::string (v->m_name );
5554+ throw SemanticError (" Only Class constructor is allowed in the object assignment for now" , target->base .loc );
5555+ }
55475556 }
55485557 tmp_vec.push_back (ASR::make_Assignment_t (al, x.base .base .loc , target, tmp_value,
55495558 overloaded));
0 commit comments