@@ -2874,20 +2874,22 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
2874
2874
if (AST::is_a<AST::ConstantStr_t>(*expr->m_value )) {
2875
2875
// It is a doc string. Skip doc strings for now.
2876
2876
continue ;
2877
- } else {
2878
- throw SemanticError (" Only doc strings allowed as expressions inside class" , expr->base .base .loc );
2879
2877
}
2880
- }
2881
- if ( AST::is_a<AST::ClassDef_t>(*x.m_body [i]) ) {
2878
+ throw SemanticError ( " Only doc strings allowed as expressions inside class " , expr-> base . base . loc );
2879
+ } else if ( AST::is_a<AST::ClassDef_t>(*x.m_body [i]) ) {
2882
2880
visit_ClassDef (*AST::down_cast<AST::ClassDef_t>(x.m_body [i]));
2883
2881
continue ;
2884
- }
2885
- if ( AST::is_a<AST::FunctionDef_t>(*x.m_body [i]) ) {
2882
+ } else if ( AST::is_a<AST::FunctionDef_t>(*x.m_body [i]) ) {
2886
2883
throw SemanticError (" Struct member functions are not supported" , x.m_body [i]->base .loc );
2884
+ } else if (AST::is_a<AST::Pass_t>(*x.m_body [i])) {
2885
+ continue ;
2886
+ } else if (!AST::is_a<AST::AnnAssign_t>(*x.m_body [i])) {
2887
+ throw SemanticError (" AnnAssign expected inside struct" , x.m_body [i]->base .loc );
2887
2888
}
2888
- LCOMPILERS_ASSERT (AST::is_a<AST::AnnAssign_t>(*x.m_body [i]));
2889
2889
AST::AnnAssign_t* ann_assign = AST::down_cast<AST::AnnAssign_t>(x.m_body [i]);
2890
- LCOMPILERS_ASSERT (AST::is_a<AST::Name_t>(*ann_assign->m_target ));
2890
+ if (!AST::is_a<AST::Name_t>(*ann_assign->m_target )) {
2891
+ throw SemanticError (" Only Name supported as target in AnnAssign inside struct" , x.m_body [i]->base .loc );
2892
+ }
2891
2893
AST::Name_t *n = AST::down_cast<AST::Name_t>(ann_assign->m_target );
2892
2894
std::string var_name = n->m_id ;
2893
2895
ASR::expr_t * init_expr = nullptr ;
0 commit comments