1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix missing check for [export] attr on a fn, without parameter (#17653)

This commit is contained in:
Felipe Pena 2023-03-15 12:17:45 -03:00 committed by GitHub
parent aa50f4ebf7
commit 2656ce9522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -95,6 +95,13 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
if node.name == 'main.main' {
c.main_fn_decl_node = *node
}
if node.language == .v && node.attrs.len > 0 {
if attr_export := node.attrs.find_first('export') {
if attr_export.arg == '' {
c.error('missing argument for [export] attribute', attr_export.pos)
}
}
}
if node.return_type != ast.void_type {
if ct_attr_idx := node.attrs.find_comptime_define() {
sexpr := node.attrs[ct_attr_idx].ct_expr.str()

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/missing_export_attr_arg_err.vv:1:1: error: missing argument for [export] attribute
1 | [export]
| ~~~~~~~~
2 | fn foo() string{
3 | return "foo"

View File

@ -0,0 +1,4 @@
[export]
fn foo() string{
return "foo"
}