diff --git a/vlib/v/checker/tests/trailing_comma_struct_attr.out b/vlib/v/checker/tests/trailing_comma_struct_attr.out index a33b49007f..0de5808839 100644 --- a/vlib/v/checker/tests/trailing_comma_struct_attr.out +++ b/vlib/v/checker/tests/trailing_comma_struct_attr.out @@ -1,6 +1,6 @@ -vlib/v/checker/tests/trailing_comma_struct_attr.vv:3:31: error: unexpected `]`, expecting `name` +vlib/v/checker/tests/trailing_comma_struct_attr.vv:3:31: error: unexpected `]`, expecting `name` 1 | struct User { 2 | name string 3 | jobs []string [json:jobss;] | ^ - 4 | } \ No newline at end of file + 4 | } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 97abf1846d..39f3dede9e 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -425,7 +425,8 @@ fn (mut p Parser) check(expected token.Kind) { if expected == .name { p.name_error = true } - p.error('unexpected `$p.tok.kind.str()`, expecting `$expected.str()`') + label := if token.is_key(p.tok.lit) { 'keyword ' } else { '' } + p.error('unexpected $label`$p.tok.kind.str()`, expecting `$expected.str()`') } } diff --git a/vlib/v/parser/tests/struct_update_err.out b/vlib/v/parser/tests/struct_update_err.out index bea1bba502..4146854c88 100644 --- a/vlib/v/parser/tests/struct_update_err.out +++ b/vlib/v/parser/tests/struct_update_err.out @@ -4,4 +4,4 @@ vlib/v/parser/tests/struct_update_err.vv:15:3: error: unexpected `...`, expectin 15 | ...f | ~~~ 16 | } - 17 | } \ No newline at end of file + 17 | } diff --git a/vlib/v/parser/tests/uncomplete_module_call_err.out b/vlib/v/parser/tests/uncomplete_module_call_err.out index e7ce008b5c..d33b0ae043 100644 --- a/vlib/v/parser/tests/uncomplete_module_call_err.out +++ b/vlib/v/parser/tests/uncomplete_module_call_err.out @@ -2,4 +2,4 @@ vlib/v/parser/tests/uncomplete_module_call_err.vv:7:1: error: unexpected `}`, ex 5 | fn main() { 6 | os. 7 | } - | ^ \ No newline at end of file + | ^ diff --git a/vlib/v/parser/tests/unexpected_keyword.out b/vlib/v/parser/tests/unexpected_keyword.out new file mode 100644 index 0000000000..4fbbade98c --- /dev/null +++ b/vlib/v/parser/tests/unexpected_keyword.out @@ -0,0 +1,7 @@ +vlib/v/parser/tests/unexpected_keyword.vv:5:12: error: unexpected keyword `import`, expecting `(` + 3 | } + 4 | + 5 | fn (s Abc) import(name string) { + | ~~~~~~ + 6 | println(name) + 7 | } diff --git a/vlib/v/parser/tests/unexpected_keyword.vv b/vlib/v/parser/tests/unexpected_keyword.vv new file mode 100644 index 0000000000..4d603034d6 --- /dev/null +++ b/vlib/v/parser/tests/unexpected_keyword.vv @@ -0,0 +1,12 @@ +struct Abc { + x int +} + +fn (s Abc) import(name string) { + println(name) +} + +fn main() { + s := Abc{} + s.import('lib') +}