From 3428257ea91d126985408214b131f764a02ada7e Mon Sep 17 00:00:00 2001 From: Swastik Date: Sat, 20 Jul 2024 18:19:35 +0530 Subject: [PATCH] improve error pos --- vlib/v/checker/checker.v | 2 +- .../tests/type_alias_decl_anon_struct_invalid_embed.out | 6 ++++++ vlib/v/parser/tests/struct_anon_invalid_embed_err.out | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 6b3c1359dd785c..acd4c41c22be4d 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -573,7 +573,7 @@ fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) { for field in parent_typ_sym.info.fields { if c.table.final_sym(field.typ).kind != .struct_ { c.error('cannot embed non-struct `${c.table.sym(field.typ).name}`', - node.type_pos) + field.type_pos) } } } diff --git a/vlib/v/checker/tests/type_alias_decl_anon_struct_invalid_embed.out b/vlib/v/checker/tests/type_alias_decl_anon_struct_invalid_embed.out index 8bb06036942b4c..663c448f30dc7b 100644 --- a/vlib/v/checker/tests/type_alias_decl_anon_struct_invalid_embed.out +++ b/vlib/v/checker/tests/type_alias_decl_anon_struct_invalid_embed.out @@ -4,3 +4,9 @@ vlib/v/checker/tests/type_alias_decl_anon_struct_invalid_embed.vv:2:16: error: c | ~~~~~~~~ 3 | Int 4 | } +vlib/v/checker/tests/type_alias_decl_anon_struct_invalid_embed.vv:3:2: error: cannot embed non-struct `Int` + 1 | type Int = int + 2 | type MyIndex = struct { + 3 | Int + | ~~~ + 4 | } diff --git a/vlib/v/parser/tests/struct_anon_invalid_embed_err.out b/vlib/v/parser/tests/struct_anon_invalid_embed_err.out index b721309274fefe..8e59b9a3d1be4a 100644 --- a/vlib/v/parser/tests/struct_anon_invalid_embed_err.out +++ b/vlib/v/parser/tests/struct_anon_invalid_embed_err.out @@ -1,6 +1,6 @@ -vlib/v/parser/tests/struct_anon_invalid_embed_err.vv:2:16: error: cannot embed non-struct `Int` +vlib/v/parser/tests/struct_anon_invalid_embed_err.vv:3:6: error: cannot embed non-struct `Int` 1 | type Int = int 2 | type MyIndex = struct { - | ~~~~~~~~ 3 | Int Int + | ~~~ 4 | }