checker: check for `x := Abc { f: fn () ? {} }` mismatch, when `f` is `fn ()`

pull/12153/head
Delyan Angelov 2021-10-11 19:20:41 +03:00
parent 6c6bb08547
commit 9fabf9f20c
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 20 additions and 0 deletions

View File

@ -144,6 +144,9 @@ pub fn (mut c Checker) check_matching_function_symbols(got_type_sym &ast.TypeSym
if got_fn.params.len != exp_fn.params.len {
return false
}
if got_fn.return_type.has_flag(.optional) != exp_fn.return_type.has_flag(.optional) {
return false
}
if !c.check_basic(got_fn.return_type, exp_fn.return_type) {
return false
}

View File

@ -0,0 +1,7 @@
vlib/v/checker/tests/fn_check_for_matching_optional_result_in_fields.vv:7:3: error: cannot assign to field `f`: expected `fn (voidptr)`, not `fn (voidptr) ?`
5 | fn main() {
6 | a := Abc{
7 | f: fn (data voidptr) ? {}
| ~~~~~~~~~~~~~~~~~~~~~~~~~
8 | }
9 | println(a)

View File

@ -0,0 +1,10 @@
struct Abc {
f fn (voidptr)
}
fn main() {
a := Abc{
f: fn (data voidptr) ? {}
}
println(a)
}