mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: show a more detailed error for invalid declarations of generic methods on generic structs.
This commit is contained in:
parent
4718b8b45a
commit
3ad22eb0dd
@ -63,8 +63,15 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
|
||||
}
|
||||
}
|
||||
if need_generic_names {
|
||||
c.error('generic function declaration must specify generic type names, e.g. foo<T>',
|
||||
node.pos)
|
||||
if node.is_method {
|
||||
c.add_error_detail('use `fn (r SomeType<T>) foo<T>() {`, not just `fn (r SomeType<T>) foo() {`')
|
||||
c.error('generic method declaration must specify generic type names',
|
||||
node.pos)
|
||||
} else {
|
||||
c.add_error_detail('use `fn foo<T>(x T) {`, not just `fn foo(x T) {`')
|
||||
c.error('generic function declaration must specify generic type names',
|
||||
node.pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
if node.language == .v && !c.is_builtin_mod && !node.is_anon {
|
||||
|
@ -1,15 +1,24 @@
|
||||
vlib/v/checker/tests/generic_fn_decl_without_generic_names_err.vv:26:1: error: generic function declaration must specify generic type names, e.g. foo<T>
|
||||
vlib/v/checker/tests/generic_fn_decl_without_generic_names_err.vv:26:1: error: generic function declaration must specify generic type names
|
||||
24 | }
|
||||
25 |
|
||||
25 |
|
||||
26 | fn g_worker(g Generic<T>) {
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
27 | t := <-g.ch
|
||||
28 | handle(t)
|
||||
vlib/v/checker/tests/generic_fn_decl_without_generic_names_err.vv:32:1: error: generic function declaration must specify generic type names, e.g. foo<T>
|
||||
Details: use `fn foo<T>(x T) {`, not just `fn foo(x T) {`
|
||||
vlib/v/checker/tests/generic_fn_decl_without_generic_names_err.vv:32:1: error: generic function declaration must specify generic type names
|
||||
30 | }
|
||||
31 |
|
||||
31 |
|
||||
32 | fn handle(t T) {
|
||||
| ~~~~~~~~~~~~~~
|
||||
33 | println("hi")
|
||||
33 | println('hi')
|
||||
34 | }
|
||||
|
||||
Details: use `fn foo<T>(x T) {`, not just `fn foo(x T) {`
|
||||
vlib/v/checker/tests/generic_fn_decl_without_generic_names_err.vv:40:1: error: generic method declaration must specify generic type names
|
||||
38 | type MayBe<T> = None | T
|
||||
39 |
|
||||
40 | fn (m MayBe<T>) is_some() bool {
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
41 | return m is T
|
||||
42 | }
|
||||
Details: use `fn (r SomeType<T>) foo<T>() {`, not just `fn (r SomeType<T>) foo() {`
|
||||
|
@ -30,5 +30,13 @@ fn g_worker(g Generic<T>) {
|
||||
}
|
||||
|
||||
fn handle(t T) {
|
||||
println("hi")
|
||||
println('hi')
|
||||
}
|
||||
|
||||
struct None {}
|
||||
|
||||
type MayBe<T> = None | T
|
||||
|
||||
fn (m MayBe<T>) is_some() bool {
|
||||
return m is T
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user