mirror of
https://github.com/vlang/v.git
synced 2025-09-15 02:18:47 -04:00
parser: suggest using type alias when defining methods on non-local types (#21803)
This commit is contained in:
parent
174257650f
commit
dd93b56b68
@ -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 }
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user