mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix anon fn initialization as struct-like (#17652)
This commit is contained in:
parent
6e1e406288
commit
2c349247e1
@ -337,6 +337,8 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini
|
|||||||
node.pos)
|
node.pos)
|
||||||
return ast.void_type
|
return ast.void_type
|
||||||
}
|
}
|
||||||
|
} else if struct_sym.info is ast.FnType {
|
||||||
|
c.error('functions must be defined, not instantiated like structs', node.pos)
|
||||||
}
|
}
|
||||||
// register generic struct type when current fn is generic fn
|
// register generic struct type when current fn is generic fn
|
||||||
if c.table.cur_fn != unsafe { nil } && c.table.cur_fn.generic_names.len > 0 {
|
if c.table.cur_fn != unsafe { nil } && c.table.cur_fn.generic_names.len > 0 {
|
||||||
|
7
vlib/v/checker/tests/wrong_fn_init_err.out
Normal file
7
vlib/v/checker/tests/wrong_fn_init_err.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
vlib/v/checker/tests/wrong_fn_init_err.vv:4:7: error: functions must be defined, not instantiated like structs
|
||||||
|
2 |
|
||||||
|
3 | fn main() {
|
||||||
|
4 | a := MyCallback{}
|
||||||
|
| ~~~~~~~~~~~~
|
||||||
|
5 | println(a)
|
||||||
|
6 | }
|
6
vlib/v/checker/tests/wrong_fn_init_err.vv
Normal file
6
vlib/v/checker/tests/wrong_fn_init_err.vv
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
type MyCallback = fn () string
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
a := MyCallback{}
|
||||||
|
println(a)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user