Skip to content

Commit

Permalink
tests: use isreftype[T]() and sizeof[T]() syntax, fix vfmt to sup…
Browse files Browse the repository at this point in the history
…port them, when written explicitly (#17103)
  • Loading branch information
Petr Makhnev committed Apr 6, 2023
1 parent 1113205 commit 812a17f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
24 changes: 12 additions & 12 deletions vlib/v/fmt/fmt.v
Expand Up @@ -2637,17 +2637,17 @@ pub fn (mut f Fmt) selector_expr(node ast.SelectorExpr) {

pub fn (mut f Fmt) size_of(node ast.SizeOf) {
f.write('sizeof')
if node.is_type {
// keep the old form for now
f.write('(')
if node.is_type && !node.guessed_type {
// 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(')')
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.write(')')
} else {
f.write('(')
f.expr(node.expr)
Expand All @@ -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) {
f.write('isreftype')
if node.is_type {
// keep the old form for now
f.write('(')
if node.is_type && !node.guessed_type {
// 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(')')
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.write(')')
} else {
f.write('(')
f.expr(node.expr)
Expand Down
4 changes: 2 additions & 2 deletions vlib/v/tests/isreftype_test.v
Expand Up @@ -29,8 +29,8 @@ fn test_isreftype() {
assert isreftype(S4) == false
assert isreftype(S5) == true
assert isreftype(f64) == false
assert isreftype([]f64) == true
assert isreftype([3]int) == false
assert isreftype[[]f64]() == true
assert isreftype[[3]int]() == false
}

fn check_ref[T]() string {
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/tests/sizeof_test.v
Expand Up @@ -16,7 +16,7 @@ fn test_math_sizeof() {

fn test_sizeof() {
assert sizeof(rune) == 4
assert sizeof([44]u8) == 44
assert sizeof[[44]u8]() == 44
assert sizeof(`€`) == 4
// depends on -m32/64
assert sizeof(S1) in [u32(4), 8]
Expand Down

0 comments on commit 812a17f

Please sign in to comment.