ci: fix more of byteptr=> &byte, vfmt check_types.v

pull/9608/head
Delyan Angelov 2021-04-05 07:27:19 +03:00
parent e9b8d9ba9e
commit 9cc9ce698f
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 21 additions and 16 deletions

View File

@ -54,31 +54,36 @@ pub fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type,
}
idx_got := got.idx()
idx_expected := expected.idx()
if idx_got in [ ast.byteptr_type_idx, ast.charptr_type_idx] || idx_expected in [ast.byteptr_type_idx, ast.charptr_type_idx] {
if idx_got in [ast.byteptr_type_idx, ast.charptr_type_idx]
|| idx_expected in [ast.byteptr_type_idx, ast.charptr_type_idx] {
igot := int(got)
iexpected := int(expected)
// TODO: remove; transitional compatibility for byteptr === &byte
if (igot == ast.byteptr_type_idx && iexpected == 65545)
|| (iexpected == ast.byteptr_type_idx && igot == 65545) {
|| (iexpected == ast.byteptr_type_idx && igot == 65545) {
return
}
// TODO: remove; transitional compatibility for charptr === &char
if (igot == ast.charptr_type_idx && iexpected == 65551)
|| (iexpected == ast.charptr_type_idx && igot == 65551) {
|| (iexpected == ast.charptr_type_idx && igot == 65551) {
return
}
muls_got := got.nr_muls()
muls_expected := expected.nr_muls()
if idx_got == ast.byteptr_type_idx && idx_expected == ast.byte_type_idx && muls_got + 1 == muls_expected {
if idx_got == ast.byteptr_type_idx && idx_expected == ast.byte_type_idx
&& muls_got + 1 == muls_expected {
return
}
if idx_expected == ast.byteptr_type_idx && idx_got == ast.byte_type_idx && muls_expected + 1 == muls_got {
if idx_expected == ast.byteptr_type_idx && idx_got == ast.byte_type_idx
&& muls_expected + 1 == muls_got {
return
}
if idx_got == ast.charptr_type_idx && idx_expected == ast.char_type_idx && muls_got + 1 == muls_expected {
if idx_got == ast.charptr_type_idx && idx_expected == ast.char_type_idx
&& muls_got + 1 == muls_expected {
return
}
if idx_expected == ast.charptr_type_idx && idx_got == ast.char_type_idx && muls_expected + 1 == muls_got {
if idx_expected == ast.charptr_type_idx && idx_got == ast.char_type_idx
&& muls_expected + 1 == muls_got {
return
}
}

View File

@ -684,7 +684,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
}
}
fn C.strtol(str charptr, endptr &&char, base int) int
fn C.strtol(str &char, endptr &&char, base int) int
fn (mut g Gen) expr(node ast.Expr) {
// println('cgen expr()')

View File

@ -15,17 +15,17 @@ fn test_offsetof() {
age: 2147483647
}
unsafe {
assert *(&string(byteptr(&cat) + __offsetof(Cat, name))) == 'Cthulhu'
assert *(&string(byteptr(&cat) + __offsetof(Cat, breed))) == 'Great Old One'
assert *(&int(byteptr(&cat) + __offsetof(Cat, age))) == 2147483647
assert *(&string(&byte(&cat) + __offsetof(Cat, name))) == 'Cthulhu'
assert *(&string(&byte(&cat) + __offsetof(Cat, breed))) == 'Great Old One'
assert *(&int(&byte(&cat) + __offsetof(Cat, age))) == 2147483647
}
}
fn test_offsetof_struct_from_another_module() {
num := complex.Complex{1.0, 1.0}
unsafe {
assert *(&f64(byteptr(&num) + __offsetof(complex.Complex, re))) == 1.0
assert *(&f64(byteptr(&num) + __offsetof(complex.Complex, im))) == 1.0
assert *(&f64(&byte(&num) + __offsetof(complex.Complex, re))) == 1.0
assert *(&f64(&byte(&num) + __offsetof(complex.Complex, im))) == 1.0
}
}
@ -36,8 +36,8 @@ fn test_offsetof_alias() {
age: 2147483647
}
unsafe {
assert *(&string(byteptr(&fel) + __offsetof(Feline, name))) == 'Cthulhu'
assert *(&string(byteptr(&fel) + __offsetof(Feline, breed))) == 'Great Old One'
assert *(&int(byteptr(&fel) + __offsetof(Feline, age))) == 2147483647
assert *(&string(&byte(&fel) + __offsetof(Feline, name))) == 'Cthulhu'
assert *(&string(&byte(&fel) + __offsetof(Feline, breed))) == 'Great Old One'
assert *(&int(&byte(&fel) + __offsetof(Feline, age))) == 2147483647
}
}