@@ -2669,9 +2669,9 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
26692669
26702670 void create_add_variable_to_scope (std::string& var_name,
26712671 ASR::ttype_t * type, const Location& loc, ASR::abiType abi,
2672- ASR::storage_typeType storage_type=ASR::storage_typeType::Default) {
2672+ ASR::storage_typeType storage_type=ASR::storage_typeType::Default,
2673+ ASR::intentType s_intent = ASRUtils::intent_local) {
26732674
2674- ASR::intentType s_intent = ASRUtils::intent_local;
26752675 ASR::abiType current_procedure_abi_type = abi;
26762676 ASR::accessType s_access = ASR::accessType::Public;
26772677 ASR::presenceType s_presence = ASR::presenceType::Required;
@@ -2891,7 +2891,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
28912891 ASR::expr_t * &init_expr,
28922892 bool wrap_derived_type_in_pointer=false ,
28932893 ASR::abiType abi=ASR::abiType::Source,
2894- bool inside_struct=false ) {
2894+ bool inside_struct=false , bool inside_class= false ) {
28952895 bool is_allocatable = false , is_const = false ;
28962896 ASR::ttype_t *type = nullptr ;
28972897 if ( inside_struct ) {
@@ -2917,8 +2917,13 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
29172917 storage_type = ASR::storage_typeType::Parameter;
29182918 }
29192919
2920- create_add_variable_to_scope (var_name, type,
2921- x.base .base .loc , abi, storage_type);
2920+ if ( inside_class ) {
2921+ create_add_variable_to_scope (var_name, type,
2922+ x.base .base .loc , abi, storage_type, ASRUtils::intent_classmember);
2923+ } else {
2924+ create_add_variable_to_scope (var_name, type,
2925+ x.base .base .loc , abi, storage_type);
2926+ }
29222927
29232928 ASR::expr_t * assign_asr_target_copy = assign_asr_target;
29242929 this ->visit_expr (*x.m_target );
@@ -3082,7 +3087,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
30823087 ASR::ttype_t * i64_type = ASRUtils::TYPE (ASR::make_Integer_t (al, x.base .base .loc , 8 ));
30833088 init_expr = ASRUtils::EXPR (ASR::make_IntegerConstant_t (al, x.base .base .loc , -1 , i64_type));
30843089 }
3085- visit_AnnAssignUtil (*ann_assign, var_name, init_expr, false , abi, true );
3090+ visit_AnnAssignUtil (*ann_assign, var_name, init_expr, false , abi, true , is_class_scope );
30863091 ASR::symbol_t * var_sym = current_scope->resolve_symbol (var_name);
30873092 ASR::call_arg_t c_arg;
30883093 c_arg.loc = var_sym->base .loc ;
@@ -5425,20 +5430,22 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
54255430 throw SemanticError (" Variable: '" + std::string (n->m_id ) + " ' is not declared" ,
54265431 x->base .loc );
54275432 }
5428- ASR::Variable_t* v = ASR::down_cast<ASR::Variable_t>(s);
5429- if (v->m_intent == ASR::intentType::In) {
5430- std::string msg = " Hint: create a new local variable with a different name" ;
5431- if (ASRUtils::is_aggregate_type (v->m_type )) {
5432- msg = " Use InOut[" + ASRUtils::type_to_str_python (v->m_type ) + " ] to allow assignment" ;
5433+ if (ASR::is_a<ASR::Variable_t>(*s)) {
5434+ ASR::Variable_t* v = ASR::down_cast<ASR::Variable_t>(s);
5435+ if (v->m_intent == ASR::intentType::In) {
5436+ std::string msg = " Hint: create a new local variable with a different name" ;
5437+ if (ASRUtils::is_aggregate_type (v->m_type )) {
5438+ msg = " Use InOut[" + ASRUtils::type_to_str_python (v->m_type ) + " ] to allow assignment" ;
5439+ }
5440+ diag.add (diag::Diagnostic (
5441+ " Assignment to an input function parameter `"
5442+ + std::string (v->m_name ) + " ` is not allowed" ,
5443+ diag::Level::Error, diag::Stage::Semantic, {
5444+ diag::Label (msg, {x->base .loc })
5445+ })
5446+ );
5447+ throw SemanticAbort ();
54335448 }
5434- diag.add (diag::Diagnostic (
5435- " Assignment to an input function parameter `"
5436- + std::string (v->m_name ) + " ` is not allowed" ,
5437- diag::Level::Error, diag::Stage::Semantic, {
5438- diag::Label (msg, {x->base .loc })
5439- })
5440- );
5441- throw SemanticAbort ();
54425449 }
54435450 return true ;
54445451 } else if (AST::is_a<AST::Subscript_t>(*x)) {
@@ -5583,15 +5590,17 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
55835590 AST::Attribute_t *attr = AST::down_cast<AST::Attribute_t>(x.m_targets [i]);
55845591 if (AST::is_a<AST::Name_t>(*attr->m_value )) {
55855592 std::string name = AST::down_cast<AST::Name_t>(attr->m_value )->m_id ;
5586- ASR::symbol_t *s = current_scope->get_symbol (name);
5593+ ASR::symbol_t *s = current_scope->resolve_symbol (name);
55875594 if (!s) {
55885595 throw SemanticError (" Variable: '" + name + " ' is not declared" ,
55895596 x.base .base .loc );
55905597 }
5591- ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(s);
5592- ASR::ttype_t *type = v->m_type ;
5593- if (ASRUtils::is_immutable (type)) {
5594- throw SemanticError (" readonly attribute" , x.base .base .loc );
5598+ if (ASR::is_a<ASR::Variable_t>(*s)) {
5599+ ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(s);
5600+ ASR::ttype_t *type = v->m_type ;
5601+ if (ASRUtils::is_immutable (type)) {
5602+ throw SemanticError (" readonly attribute" , x.base .base .loc );
5603+ }
55955604 }
55965605 }
55975606 }
@@ -6522,14 +6531,16 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
65226531 }
65236532 if ( ASR::is_a<ASR::Variable_t>(*struct_member) ) {
65246533 ASR::Variable_t* struct_member_variable = ASR::down_cast<ASR::Variable_t>(struct_member);
6525- ASR::expr_t * struct_type_var = ASRUtils::EXPR (ASR::make_Var_t (al, x.base .base .loc , org_sym));
6526- tmp = ASR::make_StructStaticMember_t (al, x.base .base .loc ,
6527- struct_type_var, struct_member, struct_member_variable->m_type ,
6528- nullptr );
6534+ if (struct_member_variable->m_intent == ASRUtils::intent_classmember) {
6535+ tmp = ASR::make_StructStaticMember_t (al, x.base .base .loc ,
6536+ s2c (al, struct_type->m_name ), struct_member, struct_member_variable->m_type ,
6537+ nullptr );
6538+ } else {
6539+ throw SemanticError (std::string (x.m_attr ) + " not a class member in " + std::string (struct_type->m_name ), x.base .base .loc );
6540+ }
65296541 } else if ( ASR::is_a<ASR::UnionType_t>(*struct_member) ) {
6530- ASR::expr_t * struct_type_var = ASRUtils::EXPR (ASR::make_Var_t (al, x.base .base .loc , org_sym));
65316542 ASR::ttype_t * union_type = ASRUtils::TYPE (ASR::make_Union_t (al, x.base .base .loc , struct_member));
6532- tmp = ASR::make_StructStaticMember_t (al, x.base .base .loc , struct_type_var , struct_member, union_type, nullptr );
6543+ tmp = ASR::make_StructStaticMember_t (al, x.base .base .loc , s2c (al, struct_type-> m_name ) , struct_member, union_type, nullptr );
65336544 }
65346545 } else if (ASR::is_a<ASR::Module_t>(*t)) {
65356546 ASR::Module_t *m = ASR::down_cast<ASR::Module_t>(t);
0 commit comments