From 90f07eb64a4418157281f3a0df6430545f3defaf Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 13 Jun 2020 00:27:05 +0800 Subject: [PATCH] parser: fix fn attributes empty error --- vlib/v/checker/tests/fn_attributes_empty_err.out | 5 +++++ vlib/v/checker/tests/fn_attributes_empty_err.vv | 6 ++++++ vlib/v/checker/tests/multiple_fn_attributes.out | 4 ++-- vlib/v/parser/parser.v | 7 ++++++- 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 vlib/v/checker/tests/fn_attributes_empty_err.out create mode 100644 vlib/v/checker/tests/fn_attributes_empty_err.vv 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] }