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:
parent
733ac05bbd
commit
9ad1c2f922
@ -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
|
||||
|
6
vlib/v/checker/tests/option_fn_field_err.out
Normal file
6
vlib/v/checker/tests/option_fn_field_err.out
Normal 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 | }
|
8
vlib/v/checker/tests/option_fn_field_err.vv
Normal file
8
vlib/v/checker/tests/option_fn_field_err.vv
Normal file
@ -0,0 +1,8 @@
|
||||
struct Foo {
|
||||
f ?fn(int)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo := Foo{}
|
||||
foo.f(1)
|
||||
}
|
Loading…
Reference in New Issue
Block a user