checker: fix fn_array types check (#7376)

pull/7405/head^2
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

@ -252,10 +252,10 @@ fn test_struct_literal_args() {
foo_config(10, {})
foo_config(10, n: 40)
foo_config(40, n: 30, def: 40)
bar_config({}, 10)
bar_config({def:4}, 4)
foo_user({
name: 'Peter'
})
@ -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]'
}