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

checker: c2v fixes for enums and pointer to numbers

This commit is contained in:
Alexander Medvednikov 2022-01-25 20:15:45 +03:00
parent 1fdbdf4a6b
commit 4715fb67c1
2 changed files with 19 additions and 2 deletions

View File

@ -171,6 +171,9 @@ fn C.tolower(c int) int
[trusted]
fn C.toupper(c int) int
[trusted]
fn C.isspace(c int) int
[trusted]
fn C.strchr(s &char, c int) &char
@ -186,6 +189,9 @@ fn C.strncasecmp(s &char, s2 &char, n int) int
[trusted]
fn C.strcasecmp(s &char, s2 &char) int
[trusted]
fn C.strncmp(s &char, s2 &char, n int) int
[trusted]
fn C.strerror(int) &char

View File

@ -11,6 +11,8 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
if got == expected {
return true
}
got_is_ptr := got.is_ptr()
exp_is_ptr := expected.is_ptr()
if c.pref.translated {
if expected == ast.byteptr_type {
return true
@ -40,9 +42,18 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
return true
}
}
if expected_sym.kind == .enum_ && got_sym.is_number() {
// Allow enums as numbers
return true
}
if got_is_ptr && exp_is_ptr {
// deref_sym := c.table.sym(expected.deref()) // set_nr_muls(0))
if expected_sym.is_number() && got_sym.is_number() {
// Allow `&&u8` used as `&&int` etc
return true
}
}
}
got_is_ptr := got.is_ptr()
exp_is_ptr := expected.is_ptr()
if got_is_ptr && exp_is_ptr {
if got.nr_muls() != expected.nr_muls() {
return false