From 812a17fb4343ad62140329931861e06d0f8b7190 Mon Sep 17 00:00:00 2001 From: Petr Makhnev <51853996+i582@users.noreply.github.com> Date: Thu, 6 Apr 2023 21:02:55 +0400 Subject: [PATCH] tests: use `isreftype[T]()` and `sizeof[T]()` syntax, fix vfmt to support them, when written explicitly (#17103) --- vlib/v/fmt/fmt.v | 32 ++++++++++++++++---------------- vlib/v/tests/isreftype_test.v | 4 ++-- vlib/v/tests/sizeof_test.v | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 858f1997a0..e694985f30 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -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('(') - f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias)) - f.write(')') - return - } - if node.is_type { + 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(']()') + return + } + if node.is_type { + f.write('(') + f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias)) + f.write(')') } else { f.write('(') 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) { f.write('isreftype') - if node.is_type { - // keep the old form for now - f.write('(') - f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias)) - f.write(')') - return - } - if node.is_type { + 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(']()') + return + } + if node.is_type { + f.write('(') + f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias)) + f.write(')') } else { f.write('(') f.expr(node.expr) diff --git a/vlib/v/tests/isreftype_test.v b/vlib/v/tests/isreftype_test.v index a56bf128e7..19c09bf082 100644 --- a/vlib/v/tests/isreftype_test.v +++ b/vlib/v/tests/isreftype_test.v @@ -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 { diff --git a/vlib/v/tests/sizeof_test.v b/vlib/v/tests/sizeof_test.v index ee59436901..8087f15d00 100644 --- a/vlib/v/tests/sizeof_test.v +++ b/vlib/v/tests/sizeof_test.v @@ -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]