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

checker: minor refactor in check_basic() (#10196)

This commit is contained in:
yuyi 2021-05-25 12:45:05 +08:00 committed by GitHub
parent 0e6f0c1de0
commit 7d210da9a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -91,17 +91,18 @@ pub fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type,
} }
pub fn (mut c Checker) check_basic(got ast.Type, expected ast.Type) bool { pub fn (mut c Checker) check_basic(got ast.Type, expected ast.Type) bool {
got_, exp_ := c.table.unalias_num_type(got), c.table.unalias_num_type(expected) unalias_got, unalias_expected := c.table.unalias_num_type(got), c.table.unalias_num_type(expected)
if got_.idx() == exp_.idx() { if unalias_got.idx() == unalias_expected.idx() {
// this is returning true even if one type is a ptr // this is returning true even if one type is a ptr
// and the other is not, is this correct behaviour? // and the other is not, is this correct behaviour?
return true return true
} }
if (exp_.is_pointer() || exp_.is_number()) && (got_.is_pointer() || got_.is_number()) { if (unalias_expected.is_pointer() || unalias_expected.is_number())
&& (unalias_got.is_pointer() || unalias_got.is_number()) {
return true return true
} }
// allow pointers to be initialized with 0. TODO: use none instead // allow pointers to be initialized with 0. TODO: use none instead
if expected.is_ptr() && got_ == ast.int_literal_type { if expected.is_ptr() && unalias_got == ast.int_literal_type {
return true return true
} }
// TODO: use sym so it can be absorbed into below [.voidptr, .any] logic // TODO: use sym so it can be absorbed into below [.voidptr, .any] logic
@ -115,7 +116,8 @@ pub fn (mut c Checker) check_basic(got ast.Type, expected ast.Type) bool {
return true return true
} }
} }
if !got_.is_ptr() && got_sym.kind == .array_fixed && (exp_.is_pointer() || exp_.is_ptr()) { if !unalias_got.is_ptr() && got_sym.kind == .array_fixed
&& (unalias_expected.is_pointer() || unalias_expected.is_ptr()) {
// fixed array needs to be a struct, not a pointer // fixed array needs to be a struct, not a pointer
return false return false
} }