Skip to content

Commit

Permalink
parser: suggest using type alias when defining methods on non-local t…
Browse files Browse the repository at this point in the history
…ypes (#21803)
  • Loading branch information
Delta456 committed Jul 5, 2024
1 parent 1742576 commit dd93b56
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion vlib/v/parser/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ run them via `v file.v` instead',
&& elem_type_sym.language == .v
}
if is_non_local {
p.error_with_pos('cannot define new methods on non-local type ${type_sym.name}',
p.error_with_pos('cannot define new methods on non-local type ${type_sym.name}. Define an alias and use that instead like `type AliasName = ${type_sym.name}` ',
rec.type_pos)
return ast.FnDecl{
scope: unsafe { nil }
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/parser/tests/method_decl_on_non_local_array.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
vlib/v/parser/tests/method_decl_on_non_local_array.vv:1:7: error: cannot define new methods on non-local type []int
vlib/v/parser/tests/method_decl_on_non_local_array.vv:1:7: error: cannot define new methods on non-local type []int. Define an alias and use that instead like `type AliasName = []int`
1 | fn (a []int) get_number() int {
| ~~~~~
2 | return 1
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/parser/tests/method_decl_on_non_local_map.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
vlib/v/parser/tests/method_decl_on_non_local_map.vv:1:7: error: cannot define new methods on non-local type map[string]string
vlib/v/parser/tests/method_decl_on_non_local_map.vv:1:7: error: cannot define new methods on non-local type map[string]string. Define an alias and use that instead like `type AliasName = map[string]string`
1 | fn (a map[string]string) get_number() int {
| ~~~~~~~~~~~~~~~~~
2 | return 1
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/parser/tests/method_decl_on_non_local_type.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
vlib/v/parser/tests/method_decl_on_non_local_type.vv:1:7: error: cannot define new methods on non-local type int
vlib/v/parser/tests/method_decl_on_non_local_type.vv:1:7: error: cannot define new methods on non-local type int. Define an alias and use that instead like `type AliasName = int`
1 | fn (a int) get_number() int {
| ~~~
2 | return 1
Expand Down

0 comments on commit dd93b56

Please sign in to comment.