@@ -3017,7 +3017,7 @@ STATIC void compile_scope_func_annotations(compiler_t *comp, mp_parse_node_t pn)
30173017 qstr arg_type = MP_PARSE_NODE_LEAF_ARG (pn_annotation );
30183018 EMIT_ARG (set_native_type , MP_EMIT_NATIVE_TYPE_ARG , id_info -> local_num , arg_type );
30193019 } else {
3020- compile_syntax_error (comp , pn_annotation , "annotation must be an identifier" );
3020+ compile_syntax_error (comp , pn_annotation , "parameter annotation must be an identifier" );
30213021 }
30223022 }
30233023 #endif // MICROPY_EMIT_NATIVE
@@ -3155,17 +3155,20 @@ STATIC void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
31553155 apply_to_single_or_list (comp , pns -> nodes [1 ], PN_typedargslist , compile_scope_func_annotations );
31563156
31573157 // pns->nodes[2] is return/whole function annotation
3158- #if MICROPY_EMIT_NATIVE
3159- if (scope -> emit_options == MP_EMIT_OPT_VIPER ) {
3160- // nodes[2] can be null or a test-expr
3161- if (MP_PARSE_NODE_IS_ID (pns -> nodes [2 ])) {
3162- qstr ret_type = MP_PARSE_NODE_LEAF_ARG (pns -> nodes [2 ]);
3163- EMIT_ARG (set_native_type , MP_EMIT_NATIVE_TYPE_RETURN , 0 , ret_type );
3164- } else {
3165- compile_syntax_error (comp , pns -> nodes [2 ], "annotation must be an identifier" );
3158+ mp_parse_node_t pn_annotation = pns -> nodes [2 ];
3159+ if (!MP_PARSE_NODE_IS_NULL (pn_annotation )) {
3160+ #if MICROPY_EMIT_NATIVE
3161+ if (scope -> emit_options == MP_EMIT_OPT_VIPER ) {
3162+ // nodes[2] can be null or a test-expr
3163+ if (MP_PARSE_NODE_IS_ID (pn_annotation )) {
3164+ qstr ret_type = MP_PARSE_NODE_LEAF_ARG (pn_annotation );
3165+ EMIT_ARG (set_native_type , MP_EMIT_NATIVE_TYPE_RETURN , 0 , ret_type );
3166+ } else {
3167+ compile_syntax_error (comp , pn_annotation , "return annotation must be an identifier" );
3168+ }
31663169 }
3170+ #endif // MICROPY_EMIT_NATIVE
31673171 }
3168- #endif // MICROPY_EMIT_NATIVE
31693172 }
31703173
31713174 compile_node (comp , pns -> nodes [3 ]); // 3 is function body
@@ -3625,7 +3628,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, uint emit_opt, bool is
36253628 comp -> emit_method_table = & emit_native_thumb_method_table ;
36263629#endif
36273630 comp -> emit = emit_native ;
3628- comp -> emit_method_table -> set_native_type ( comp -> emit , MP_EMIT_NATIVE_TYPE_ENABLE , s -> emit_options == MP_EMIT_OPT_VIPER , 0 );
3631+ EMIT_ARG ( set_native_type , MP_EMIT_NATIVE_TYPE_ENABLE , s -> emit_options == MP_EMIT_OPT_VIPER , 0 );
36293632
36303633 // native emitters need an extra pass to compute stack size
36313634 compile_scope (comp , s , MP_PASS_STACK_SIZE );
0 commit comments