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

tests: use isreftype[T]() and sizeof[T]() syntax, fix vfmt to support them, when written explicitly (#17103)

This commit is contained in:
Petr Makhnev 2023-04-06 21:02:55 +04:00 committed by GitHub
parent 1113205376
commit 812a17fb43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 19 deletions

View File

@ -2637,17 +2637,17 @@ pub fn (mut f Fmt) selector_expr(node ast.SelectorExpr) {
pub fn (mut f Fmt) size_of(node ast.SizeOf) { pub fn (mut f Fmt) size_of(node ast.SizeOf) {
f.write('sizeof') f.write('sizeof')
if node.is_type { if node.is_type && !node.guessed_type {
// keep the old form for now // the new form was explicitly written in the source code; keep it:
f.write('(')
f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias))
f.write(')')
return
}
if node.is_type {
f.write('[') f.write('[')
f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias)) f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias))
f.write(']()') f.write(']()')
return
}
if node.is_type {
f.write('(')
f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias))
f.write(')')
} else { } else {
f.write('(') f.write('(')
f.expr(node.expr) f.expr(node.expr)
@ -2657,17 +2657,17 @@ pub fn (mut f Fmt) size_of(node ast.SizeOf) {
pub fn (mut f Fmt) is_ref_type(node ast.IsRefType) { pub fn (mut f Fmt) is_ref_type(node ast.IsRefType) {
f.write('isreftype') f.write('isreftype')
if node.is_type { if node.is_type && !node.guessed_type {
// keep the old form for now // the new form was explicitly written in the source code; keep it:
f.write('(')
f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias))
f.write(')')
return
}
if node.is_type {
f.write('[') f.write('[')
f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias)) f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias))
f.write(']()') f.write(']()')
return
}
if node.is_type {
f.write('(')
f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias))
f.write(')')
} else { } else {
f.write('(') f.write('(')
f.expr(node.expr) f.expr(node.expr)

View File

@ -29,8 +29,8 @@ fn test_isreftype() {
assert isreftype(S4) == false assert isreftype(S4) == false
assert isreftype(S5) == true assert isreftype(S5) == true
assert isreftype(f64) == false assert isreftype(f64) == false
assert isreftype([]f64) == true assert isreftype[[]f64]() == true
assert isreftype([3]int) == false assert isreftype[[3]int]() == false
} }
fn check_ref[T]() string { fn check_ref[T]() string {

View File

@ -16,7 +16,7 @@ fn test_math_sizeof() {
fn test_sizeof() { fn test_sizeof() {
assert sizeof(rune) == 4 assert sizeof(rune) == 4
assert sizeof([44]u8) == 44 assert sizeof[[44]u8]() == 44
assert sizeof(``) == 4 assert sizeof(``) == 4
// depends on -m32/64 // depends on -m32/64
assert sizeof(S1) in [u32(4), 8] assert sizeof(S1) in [u32(4), 8]