checker: allow to use [n]anyptr as [n]otherptr in check_types (c2v fix) (#14433)

master
playX 2022-05-17 08:55:04 +00:00 committed by GitHub
parent 78ab3296c9
commit 7c6eaa8204
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

View File

@ -44,6 +44,20 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
} }
got_sym := c.table.sym(got) got_sym := c.table.sym(got)
expected_sym := c.table.sym(expected) expected_sym := c.table.sym(expected)
// Allow `[N]anyptr` as `[N]anyptr`
if got_sym.kind == .array && expected_sym.kind == .array {
if (got_sym.info as ast.Array).elem_type.is_any_kind_of_pointer()
&& (expected_sym.info as ast.Array).elem_type.is_any_kind_of_pointer() {
return true
}
} else if got_sym.kind == .array_fixed && expected_sym.kind == .array_fixed {
if (got_sym.info as ast.ArrayFixed).elem_type.is_any_kind_of_pointer()
&& (expected_sym.info as ast.ArrayFixed).elem_type.is_any_kind_of_pointer() {
return true
}
}
if got_sym.kind == .enum_ { if got_sym.kind == .enum_ {
// Allow ints as enums // Allow ints as enums
if expected_sym.is_number() { if expected_sym.is_number() {