From f2be115f7df2c63bbaa866531d4a6252ed231a7b Mon Sep 17 00:00:00 2001 From: yuyi Date: Wed, 29 Jun 2022 21:14:03 +0800 Subject: [PATCH] parser: fix the incorrect location of the type declaration name (#14879) --- vlib/v/parser/parser.v | 4 ++-- vlib/v/parser/tests/type_decl_name_err.out | 5 +++++ vlib/v/parser/tests/type_decl_name_err.vv | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 vlib/v/parser/tests/type_decl_name_err.out create mode 100644 vlib/v/parser/tests/type_decl_name_err.vv diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 26ec2e3f25..f7122bb45f 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -3674,8 +3674,8 @@ fn (mut p Parser) type_decl() ast.TypeDecl { } name := p.check_name() if name.len == 1 && name[0].is_capital() { - p.error_with_pos('single letter capital names are reserved for generic template types.', - decl_pos) + p.error_with_pos('single letter capital names are reserved for generic template types', + name_pos) return ast.FnTypeDecl{} } if name in p.imported_symbols { diff --git a/vlib/v/parser/tests/type_decl_name_err.out b/vlib/v/parser/tests/type_decl_name_err.out new file mode 100644 index 0000000000..b74c638e44 --- /dev/null +++ b/vlib/v/parser/tests/type_decl_name_err.out @@ -0,0 +1,5 @@ +vlib/v/parser/tests/type_decl_name_err.vv:1:6: error: single letter capital names are reserved for generic template types + 1 | type A = int | string + | ^ + 2 | + 3 | fn main() { diff --git a/vlib/v/parser/tests/type_decl_name_err.vv b/vlib/v/parser/tests/type_decl_name_err.vv new file mode 100644 index 0000000000..cc2faddb24 --- /dev/null +++ b/vlib/v/parser/tests/type_decl_name_err.vv @@ -0,0 +1,6 @@ +type A = int | string + +fn main() { + a := A(11) + println(a) +}