@@ -1581,6 +1581,26 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
1581
1581
}
1582
1582
}
1583
1583
1584
+ AST::expr_t * get_var_intent_and_annotation (AST::expr_t *annotation, ASR::intentType &intent) {
1585
+ if (AST::is_a<AST::Subscript_t>(*annotation)) {
1586
+ AST::Subscript_t *s = AST::down_cast<AST::Subscript_t>(annotation);
1587
+ if (AST::is_a<AST::Name_t>(*s->m_value )) {
1588
+ std::string ann_name = AST::down_cast<AST::Name_t>(s->m_value )->m_id ;
1589
+ if (ann_name == " In" ) {
1590
+ intent = ASRUtils::intent_in;
1591
+ } else if (ann_name == " InOut" ) {
1592
+ intent = ASRUtils::intent_inout;
1593
+ } else if (ann_name == " Out" ) {
1594
+ intent = ASRUtils::intent_out;
1595
+ }
1596
+ return s->m_slice ;
1597
+ } else {
1598
+ throw SemanticError (" Only Name in Subscript supported for now in annotation" , annotation->base .loc );
1599
+ }
1600
+ }
1601
+ return annotation;
1602
+ }
1603
+
1584
1604
// Convert Python AST type annotation to an ASR type
1585
1605
// Examples:
1586
1606
// i32, i64, f32, f64
@@ -3741,7 +3761,9 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
3741
3761
if (x.m_args .m_args [i].m_annotation == nullptr ) {
3742
3762
throw SemanticError (" Argument does not have a type" , loc);
3743
3763
}
3744
- ASR::ttype_t *arg_type = ast_expr_to_asr_type (x.base .base .loc , *x.m_args .m_args [i].m_annotation );
3764
+ ASR::intentType s_intent = ASRUtils::intent_in;
3765
+ AST::expr_t * arg_annotation_type = get_var_intent_and_annotation (x.m_args .m_args [i].m_annotation , s_intent);
3766
+ ASR::ttype_t *arg_type = ast_expr_to_asr_type (x.base .base .loc , *arg_annotation_type);
3745
3767
// Set the function as generic if an argument is typed with a type parameter
3746
3768
if (ASRUtils::is_generic (*arg_type)) {
3747
3769
ASR::ttype_t * arg_type_type = ASRUtils::get_type_parameter (arg_type);
@@ -3766,10 +3788,8 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
3766
3788
}
3767
3789
3768
3790
std::string arg_s = arg;
3769
-
3770
3791
ASR::expr_t *value = nullptr ;
3771
3792
ASR::expr_t *init_expr = nullptr ;
3772
- ASR::intentType s_intent = ASRUtils::intent_in;
3773
3793
if (ASRUtils::is_array (arg_type)) {
3774
3794
s_intent = ASRUtils::intent_inout;
3775
3795
}
0 commit comments