diff --git a/vlib/v/checker/tests/fn_attributes_empty_err.out b/vlib/v/checker/tests/fn_attributes_empty_err.out new file mode 100644 index 0000000000..71e37e87d1 --- /dev/null +++ b/vlib/v/checker/tests/fn_attributes_empty_err.out @@ -0,0 +1,5 @@ +vlib/v/checker/tests/fn_attributes_empty_err.v:1:1: error: attributes cannot be empty + 1 | [] fn tt() { + | ~~ + 2 | println('text') + 3 | } diff --git a/vlib/v/checker/tests/fn_attributes_empty_err.vv b/vlib/v/checker/tests/fn_attributes_empty_err.vv new file mode 100644 index 0000000000..fd584c2972 --- /dev/null +++ b/vlib/v/checker/tests/fn_attributes_empty_err.vv @@ -0,0 +1,6 @@ +[] fn tt() { + println('text') +} +fn main() { + tt() +} \ No newline at end of file diff --git a/vlib/v/checker/tests/multiple_fn_attributes.out b/vlib/v/checker/tests/multiple_fn_attributes.out index 74bee779f4..b2e2e15528 100644 --- a/vlib/v/checker/tests/multiple_fn_attributes.out +++ b/vlib/v/checker/tests/multiple_fn_attributes.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/multiple_fn_attributes.v:2:1: error: multiple attributes detected +vlib/v/checker/tests/multiple_fn_attributes.v:1:1: error: multiple attributes detected 1 | [inline;deprecated] + | ~~~~~~~~~~~~~~~~~~~ 2 | fn foo(name string) string {} - | ~~ \ No newline at end of file diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 3fe61e1b6a..2e3309ec42 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -407,9 +407,14 @@ pub fn (mut p Parser) top_stmt() ast.Stmt { } } .lsbr { + start_pos := p.tok.position() attrs := p.attributes() if attrs.len > 1 { - p.error('multiple attributes detected') + end_pos := p.tok.position() + p.error_with_pos('multiple attributes detected', start_pos.extend(end_pos)) + } else if attrs.len == 0 { + end_pos := p.tok.position() + p.error_with_pos('attributes cannot be empty', start_pos.extend(end_pos)) } return attrs[0] }