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

checker: fix fn_array types check (#7376)

This commit is contained in:
yuyi 2020-12-19 07:10:11 +08:00 committed by GitHub
parent 042449cd3d
commit ff2cfd4f38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 6 deletions

View File

@ -74,10 +74,12 @@ pub fn (mut c Checker) check_basic(got table.Type, expected table.Type) bool {
(exp_type_sym.is_int() && got_type_sym.kind == .enum_) {
return true
}
// TODO
// if got_type_sym.kind == .array && exp_type_sym.kind == .array {
// return true
// }
// array fn
if got_type_sym.kind == .array && exp_type_sym.kind == .array {
if c.table.type_to_str(got) == c.table.type_to_str(expected) {
return true
}
}
if got_type_sym.kind == .array_fixed && exp_type_sym.kind == .byteptr {
info := got_type_sym.info as table.ArrayFixed
if info.elem_type.idx() == table.byte_type_idx {

View File

@ -349,3 +349,20 @@ fn test_fields_anon_fn_with_optional_void_return_type() {
}
}
struct Commands {
show []fn() string
}
fn a() string {
return 'HELLOW'
}
fn b() string {
return 'WOLLEH'
}
fn test_fields_array_of_fn() {
commands := Commands{show: [a, b]}
println(commands.show)
assert '$commands.show' == '[fn () string, fn () string]'
}