1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix missing option function field checking (#17601)

This commit is contained in:
Felipe Pena 2023-03-13 11:05:56 -03:00 committed by GitHub
parent 733ac05bbd
commit 9ad1c2f922
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

View File

@ -1899,6 +1899,9 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
// call struct field fn type
// TODO: can we use SelectorExpr for all? this dosent really belong here
if field := c.table.find_field_with_embeds(left_sym, method_name) {
if field.typ.has_flag(.option) {
c.error('Option function field must be unwrapped first', node.pos)
}
field_sym := c.table.sym(c.unwrap_generic(field.typ))
if field_sym.kind == .function {
node.is_method = false

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/option_fn_field_err.vv:7:6: error: Option function field must be unwrapped first
5 | fn main() {
6 | foo := Foo{}
7 | foo.f(1)
| ~~~~
8 | }

View File

@ -0,0 +1,8 @@
struct Foo {
f ?fn(int)
}
fn main() {
foo := Foo{}
foo.f(1)
}