From a741db43f388822bd078daa617d285ed6cf7766b Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 10 Aug 2024 22:04:49 +0300 Subject: [PATCH] checker: add a deprecation warning for `const ()` groups (an error after 2025-01-01) (#22019) --- cmd/tools/vcreate/project_model_web.v | 4 +- vlib/regex/regex_test.v | 27 +-- vlib/v/ast/str.v | 5 +- vlib/v/checker/checker.v | 4 + .../tests/const_decl_multi_return_err.out | 14 +- .../tests/const_decl_multi_return_err.vv | 7 +- .../tests/const_define_in_function_err.out | 2 +- .../tests/const_define_in_function_err.vv | 2 +- vlib/v/checker/tests/const_field_add_err.out | 10 +- vlib/v/checker/tests/const_field_add_err.vv | 4 +- vlib/v/checker/tests/const_field_dec_err.out | 10 +- vlib/v/checker/tests/const_field_dec_err.vv | 4 +- vlib/v/checker/tests/const_field_inc_err.out | 10 +- vlib/v/checker/tests/const_field_inc_err.vv | 4 +- .../tests/const_field_name_duplicate_err.out | 13 +- .../tests/const_field_name_duplicate_err.vv | 7 +- .../tests/const_field_name_snake_case.out | 11 +- .../tests/const_field_name_snake_case.vv | 5 +- vlib/v/checker/tests/const_field_sub_err.out | 10 +- vlib/v/checker/tests/const_field_sub_err.vv | 4 +- .../globals/name_conflict_with_const.out | 11 +- .../tests/globals/name_conflict_with_const.vv | 8 +- .../tests/if_diff_expected_type_err.out | 12 +- .../tests/if_diff_expected_type_err.vv | 8 +- vlib/v/checker/tests/incorrect_name_const.vv | 4 +- vlib/v/checker/tests/lock_const.out | 12 +- vlib/v/checker/tests/lock_const.vv | 4 +- ...cast_cond_not_same_range_cast_type_err.out | 12 +- ..._cast_cond_not_same_range_cast_type_err.vv | 7 +- .../tests/match_ranges_not_same_cast_err.out | 12 +- .../tests/match_ranges_not_same_cast_err.vv | 7 +- .../multi_const_field_name_duplicate_err.out | 12 +- .../multi_const_field_name_duplicate_err.vv | 5 +- vlib/v/checker/tests/option_fn_err.out | 216 +++++++++--------- vlib/v/checker/tests/option_fn_err.vv | 4 +- .../tests/orm_limit_less_than_zero_error.out | 12 +- .../tests/orm_limit_less_than_zero_error.vv | 6 +- .../tests/reserved_type_name_const_err.out | 11 +- .../tests/reserved_type_name_const_err.vv | 4 +- vlib/v/checker/tests/var_eval_not_used.out | 10 +- vlib/v/checker/tests/var_eval_not_used.vv | 4 +- .../checker/tests/var_eval_not_used_scope.out | 12 +- .../checker/tests/var_eval_not_used_scope.vv | 4 +- .../slow_tests/inout/printing_const_array.vv | 8 +- vlib/v2/gen/v/gen.v | 11 +- vlib/vweb/csrf/README.md | 17 +- 46 files changed, 268 insertions(+), 322 deletions(-) diff --git a/cmd/tools/vcreate/project_model_web.v b/cmd/tools/vcreate/project_model_web.v index 0c07c8644..4758234dc 100644 --- a/cmd/tools/vcreate/project_model_web.v +++ b/cmd/tools/vcreate/project_model_web.v @@ -355,9 +355,7 @@ import vweb import databases import os -const ( - port = 8082 -) +const port = 8082 struct App { vweb.Context diff --git a/vlib/regex/regex_test.v b/vlib/regex/regex_test.v index 3ed9cc86e..564e45c97 100644 --- a/vlib/regex/regex_test.v +++ b/vlib/regex/regex_test.v @@ -17,8 +17,7 @@ struct TestItem { } // vfmt off -const( -match_test_suite = [ +const match_test_suite = [ // minus in CC TestItem{"d.def",r"abc.\.[\w\-]{,100}",-1,0}, TestItem{"abc12345.asd",r"abc.\.[\w\-]{,100}",-1,4}, @@ -203,10 +202,8 @@ match_test_suite = [ TestItem{"abcAAxyz", r"^abc\X4141xyz$", 0,8}, TestItem{"abcALxyz", r"^abc\X414cxyz$", 0,8}, TestItem{"abcALxyz", r"^abc\X414Cxyz$", 0,8}, - TestItem{"abcBxyz", r"^abc\x41+xyz$", -1,3}, - + TestItem{"abcBxyz", r"^abc\x41+xyz$", -1,3}, ] -) struct TestItemRe { src string @@ -215,8 +212,7 @@ struct TestItemRe { r string } -const ( -match_test_suite_replace = [ +const match_test_suite_replace = [ // replace tests TestItemRe{ "oggi pibao è andato a casa di pbababao ed ha trovato pibabababao", @@ -250,7 +246,7 @@ match_test_suite_replace = [ }, ] -match_test_suite_replace_simple = [ +const match_test_suite_replace_simple = [ // replace tests TestItemRe{ "oggi pibao è andato a casa di pbababao ed ha trovato pibabababao", @@ -265,7 +261,6 @@ match_test_suite_replace_simple = [ "CIAO is a good day and CIAO will be for sure." }, ] -) struct TestItemCGroup { src string @@ -276,8 +271,7 @@ struct TestItemCGroup { cgn map[string]int } -const ( -cgroups_test_suite = [ +const cgroups_test_suite = [ TestItemCGroup{ "http://www.ciao.mondo/hello/pippo12_/pera.html", r"(?Phttps?)|(?:ftps?)://(?P[\w_]+[\.|/])+",0,42, @@ -316,7 +310,6 @@ cgroups_test_suite = [ map[string]int{} }, ] -) struct Test_find_all { src string @@ -325,8 +318,7 @@ struct Test_find_all { res_str []string // ['find0','find1'...] } -const ( -find_all_test_suite = [ +const find_all_test_suite = [ Test_find_all{ "abcd 1234 efgh 1234 ghkl1234 ab34546df", r"\d+", @@ -417,9 +409,8 @@ find_all_test_suite = [ [0, 2], ['ab'] } - ] -) + struct Test_split { src string @@ -427,8 +418,7 @@ struct Test_split { res []string // ['abc','def',...] } -const ( - split_test_suite = [ +const split_test_suite = [ Test_split{'abcd 1234 efgh 1234 ghkl1234 ab34546df', r'\d+', ['abcd ', ' efgh ', ' ghkl', ' ab', 'df']}, Test_split{'abcd 1234 efgh 1234 ghkl1234 ab34546df', r'\a+', ['', ' 1234 ', ' 1234 ', '1234 ', @@ -457,7 +447,6 @@ const ( Test_split{'a-', r'-', ['a', '']}, Test_split{'-a', r'-', ['', 'a']}, ] -) // vfmt on fn test_regex() { diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index 0e8992a99..5acbeda93 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -756,8 +756,7 @@ pub fn (node Stmt) str() string { return node.str() } ConstDecl { - fields := node.fields.map(field_to_string) - return 'const (${fields.join(' ')})' + return node.fields.map(field_to_string).join('') } DeferStmt { mut res := '' @@ -870,7 +869,7 @@ pub fn (node Stmt) str() string { fn field_to_string(f ConstField) string { x := f.name.trim_string_left(f.mod + '.') - return '${x} = ${f.expr}' + return 'const ${x} = ${f.expr};' } pub fn (e ComptimeForKind) str() string { diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 983b397b1..f20ec48b3 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1753,6 +1753,10 @@ fn (mut c Checker) const_decl(mut node ast.ConstDecl) { if node.fields.len == 0 { c.warn('const block must have at least 1 declaration', node.pos) } + if node.is_block { + c.warn('const () groups will be an error after 2025-01-01 (`v fmt -w source.v` will fix that for you)', + node.pos) + } for mut field in node.fields { if checker.reserved_type_names_chk.matches(util.no_cur_mod(field.name, c.mod)) { c.error('invalid use of reserved type `${field.name}` as a const name', field.pos) diff --git a/vlib/v/checker/tests/const_decl_multi_return_err.out b/vlib/v/checker/tests/const_decl_multi_return_err.out index 8e56bee1c..231f5eba7 100644 --- a/vlib/v/checker/tests/const_decl_multi_return_err.out +++ b/vlib/v/checker/tests/const_decl_multi_return_err.out @@ -1,7 +1,7 @@ -vlib/v/checker/tests/const_decl_multi_return_err.vv:6:6: error: const declarations do not support multiple return values yet - 4 | - 5 | const ( - 6 | a = foo() - | ~~~~~ - 7 | ) - 8 | \ No newline at end of file +vlib/v/checker/tests/const_decl_multi_return_err.vv:5:11: error: const declarations do not support multiple return values yet + 3 | } + 4 | + 5 | const a = foo() + | ~~~~~ + 6 | + 7 | fn main() { diff --git a/vlib/v/checker/tests/const_decl_multi_return_err.vv b/vlib/v/checker/tests/const_decl_multi_return_err.vv index 663949e52..aeb7c4de2 100644 --- a/vlib/v/checker/tests/const_decl_multi_return_err.vv +++ b/vlib/v/checker/tests/const_decl_multi_return_err.vv @@ -2,11 +2,8 @@ fn foo() (int, int, int) { return 1, 2, 3 } -const ( - a = foo() -) - +const a = foo() fn main() { - println("$a") + println('${a}') } diff --git a/vlib/v/checker/tests/const_define_in_function_err.out b/vlib/v/checker/tests/const_define_in_function_err.out index e3b3544b5..16d436ddd 100644 --- a/vlib/v/checker/tests/const_define_in_function_err.out +++ b/vlib/v/checker/tests/const_define_in_function_err.out @@ -1,6 +1,6 @@ vlib/v/checker/tests/const_define_in_function_err.vv:2:2: error: const can only be defined at the top level (outside of functions) 1 | fn main() { - 2 | const (a = 1) + 2 | const a = 1 | ~~~~~ 3 | println(a) 4 | } diff --git a/vlib/v/checker/tests/const_define_in_function_err.vv b/vlib/v/checker/tests/const_define_in_function_err.vv index e6da54807..3aaaef3a8 100644 --- a/vlib/v/checker/tests/const_define_in_function_err.vv +++ b/vlib/v/checker/tests/const_define_in_function_err.vv @@ -1,4 +1,4 @@ fn main() { - const (a = 1) + const a = 1 println(a) } diff --git a/vlib/v/checker/tests/const_field_add_err.out b/vlib/v/checker/tests/const_field_add_err.out index 12505828f..80890a46b 100644 --- a/vlib/v/checker/tests/const_field_add_err.out +++ b/vlib/v/checker/tests/const_field_add_err.out @@ -1,6 +1,6 @@ -vlib/v/checker/tests/const_field_add_err.vv:6:2: error: cannot modify constant `a` - 4 | - 5 | fn main() { - 6 | a += 1 +vlib/v/checker/tests/const_field_add_err.vv:4:2: error: cannot modify constant `a` + 2 | + 3 | fn main() { + 4 | a += 1 | ^ - 7 | } + 5 | } diff --git a/vlib/v/checker/tests/const_field_add_err.vv b/vlib/v/checker/tests/const_field_add_err.vv index 24a6bb5e9..1caed69ae 100644 --- a/vlib/v/checker/tests/const_field_add_err.vv +++ b/vlib/v/checker/tests/const_field_add_err.vv @@ -1,6 +1,4 @@ -const ( - a = 1 -) +const a = 1 fn main() { a += 1 diff --git a/vlib/v/checker/tests/const_field_dec_err.out b/vlib/v/checker/tests/const_field_dec_err.out index e0b9acb42..785971e23 100644 --- a/vlib/v/checker/tests/const_field_dec_err.out +++ b/vlib/v/checker/tests/const_field_dec_err.out @@ -1,6 +1,6 @@ -vlib/v/checker/tests/const_field_dec_err.vv:6:2: error: cannot modify constant `a` - 4 | - 5 | fn main() { - 6 | a-- +vlib/v/checker/tests/const_field_dec_err.vv:4:2: error: cannot modify constant `a` + 2 | + 3 | fn main() { + 4 | a-- | ^ - 7 | } + 5 | } diff --git a/vlib/v/checker/tests/const_field_dec_err.vv b/vlib/v/checker/tests/const_field_dec_err.vv index 0f9983989..f30b30f91 100644 --- a/vlib/v/checker/tests/const_field_dec_err.vv +++ b/vlib/v/checker/tests/const_field_dec_err.vv @@ -1,6 +1,4 @@ -const ( - a = 1 -) +const a = 1 fn main() { a-- diff --git a/vlib/v/checker/tests/const_field_inc_err.out b/vlib/v/checker/tests/const_field_inc_err.out index adeee6035..ffe6431b0 100644 --- a/vlib/v/checker/tests/const_field_inc_err.out +++ b/vlib/v/checker/tests/const_field_inc_err.out @@ -1,6 +1,6 @@ -vlib/v/checker/tests/const_field_inc_err.vv:6:2: error: cannot modify constant `a` - 4 | - 5 | fn main() { - 6 | a++ +vlib/v/checker/tests/const_field_inc_err.vv:4:2: error: cannot modify constant `a` + 2 | + 3 | fn main() { + 4 | a++ | ^ - 7 | } + 5 | } diff --git a/vlib/v/checker/tests/const_field_inc_err.vv b/vlib/v/checker/tests/const_field_inc_err.vv index 9d0d96e74..ff67a9535 100644 --- a/vlib/v/checker/tests/const_field_inc_err.vv +++ b/vlib/v/checker/tests/const_field_inc_err.vv @@ -1,6 +1,4 @@ -const ( - a = 1 -) +const a = 1 fn main() { a++ diff --git a/vlib/v/checker/tests/const_field_name_duplicate_err.out b/vlib/v/checker/tests/const_field_name_duplicate_err.out index e887c1392..35bcf4c36 100644 --- a/vlib/v/checker/tests/const_field_name_duplicate_err.out +++ b/vlib/v/checker/tests/const_field_name_duplicate_err.out @@ -1,7 +1,6 @@ -vlib/v/checker/tests/const_field_name_duplicate_err.vv:3:2: error: duplicate const `aaa` - 1 | const ( - 2 | aaa = 1 - 3 | aaa = 2 - | ~~~ - 4 | ) - 5 | fn main() { +vlib/v/checker/tests/const_field_name_duplicate_err.vv:2:1: error: unexpected name `cosnt` + 1 | const aaa = 1 + 2 | cosnt aaa = 2 + | ~~~~~ + 3 | + 4 | fn main() { diff --git a/vlib/v/checker/tests/const_field_name_duplicate_err.vv b/vlib/v/checker/tests/const_field_name_duplicate_err.vv index f489f5167..0335f2da2 100644 --- a/vlib/v/checker/tests/const_field_name_duplicate_err.vv +++ b/vlib/v/checker/tests/const_field_name_duplicate_err.vv @@ -1,7 +1,6 @@ -const ( - aaa = 1 - aaa = 2 -) +const aaa = 1 +cosnt aaa = 2 + fn main() { println(aaa) } diff --git a/vlib/v/checker/tests/const_field_name_snake_case.out b/vlib/v/checker/tests/const_field_name_snake_case.out index 352ff4bf6..a089725dd 100644 --- a/vlib/v/checker/tests/const_field_name_snake_case.out +++ b/vlib/v/checker/tests/const_field_name_snake_case.out @@ -1,6 +1,5 @@ -vlib/v/checker/tests/const_field_name_snake_case.vv:2:2: error: const names cannot contain uppercase letters, use snake_case instead - 1 | const ( - 2 | Red = 1 - | ~~~ - 3 | ) - 4 | fn main() { println(Red) } +vlib/v/checker/tests/const_field_name_snake_case.vv:1:7: error: const names cannot contain uppercase letters, use snake_case instead + 1 | const Red = 1 + | ~~~ + 2 | + 3 | fn main() { println(Red) } diff --git a/vlib/v/checker/tests/const_field_name_snake_case.vv b/vlib/v/checker/tests/const_field_name_snake_case.vv index cd8af8eb0..8971f295c 100644 --- a/vlib/v/checker/tests/const_field_name_snake_case.vv +++ b/vlib/v/checker/tests/const_field_name_snake_case.vv @@ -1,4 +1,3 @@ -const ( - Red = 1 -) +const Red = 1 + fn main() { println(Red) } diff --git a/vlib/v/checker/tests/const_field_sub_err.out b/vlib/v/checker/tests/const_field_sub_err.out index 782520b8e..e9e5dba75 100644 --- a/vlib/v/checker/tests/const_field_sub_err.out +++ b/vlib/v/checker/tests/const_field_sub_err.out @@ -1,6 +1,6 @@ -vlib/v/checker/tests/const_field_sub_err.vv:6:2: error: cannot modify constant `a` - 4 | - 5 | fn main() { - 6 | a -= 1 +vlib/v/checker/tests/const_field_sub_err.vv:4:2: error: cannot modify constant `a` + 2 | + 3 | fn main() { + 4 | a -= 1 | ^ - 7 | } + 5 | } diff --git a/vlib/v/checker/tests/const_field_sub_err.vv b/vlib/v/checker/tests/const_field_sub_err.vv index e6c021bf7..e8ac5135a 100644 --- a/vlib/v/checker/tests/const_field_sub_err.vv +++ b/vlib/v/checker/tests/const_field_sub_err.vv @@ -1,6 +1,4 @@ -const ( - a = 1 -) +const a = 1 fn main() { a -= 1 diff --git a/vlib/v/checker/tests/globals/name_conflict_with_const.out b/vlib/v/checker/tests/globals/name_conflict_with_const.out index 031a0400a..1dbc5542a 100644 --- a/vlib/v/checker/tests/globals/name_conflict_with_const.out +++ b/vlib/v/checker/tests/globals/name_conflict_with_const.out @@ -1,6 +1,5 @@ -vlib/v/checker/tests/globals/name_conflict_with_const.vv:6:2: error: duplicate global and const `foo` - 4 | - 5 | __global ( - 6 | foo = 123 - | ~~~ - 7 | ) +vlib/v/checker/tests/globals/name_conflict_with_const.vv:3:10: error: duplicate global and const `foo` + 1 | const foo = 'abc' + 2 | + 3 | __global foo = 123 + | ~~~ diff --git a/vlib/v/checker/tests/globals/name_conflict_with_const.vv b/vlib/v/checker/tests/globals/name_conflict_with_const.vv index 4fa5c4389..7118da6f0 100644 --- a/vlib/v/checker/tests/globals/name_conflict_with_const.vv +++ b/vlib/v/checker/tests/globals/name_conflict_with_const.vv @@ -1,7 +1,3 @@ -const ( - foo = 'abc' -) +const foo = 'abc' -__global ( - foo = 123 -) +__global foo = 123 diff --git a/vlib/v/checker/tests/if_diff_expected_type_err.out b/vlib/v/checker/tests/if_diff_expected_type_err.out index 54ade22fd..db5bc60ca 100644 --- a/vlib/v/checker/tests/if_diff_expected_type_err.out +++ b/vlib/v/checker/tests/if_diff_expected_type_err.out @@ -1,7 +1,7 @@ -vlib/v/checker/tests/if_diff_expected_type_err.vv:7:11: error: mismatched types `&[]rune` and `[]rune` - 5 | - 6 | fn main() { - 7 | runes := if true { &some_runes } else { some_other_runes } +vlib/v/checker/tests/if_diff_expected_type_err.vv:5:11: error: mismatched types `&[]rune` and `[]rune` + 3 | + 4 | fn main() { + 5 | runes := if true { &some_runes } else { some_other_runes } | ~~ - 8 | println(runes) - 9 | } + 6 | println(runes) + 7 | } diff --git a/vlib/v/checker/tests/if_diff_expected_type_err.vv b/vlib/v/checker/tests/if_diff_expected_type_err.vv index 963e46bcb..68a9451d5 100644 --- a/vlib/v/checker/tests/if_diff_expected_type_err.vv +++ b/vlib/v/checker/tests/if_diff_expected_type_err.vv @@ -1,9 +1,7 @@ -const ( - some_runes = [`a`, `b`, `c`] - some_other_runes = [`c`, `b`, `a`] -) +const some_runes = [`a`, `b`, `c`] +const some_other_runes = [`c`, `b`, `a`] fn main() { runes := if true { &some_runes } else { some_other_runes } println(runes) -} \ No newline at end of file +} diff --git a/vlib/v/checker/tests/incorrect_name_const.vv b/vlib/v/checker/tests/incorrect_name_const.vv index 50f553f76..11980a39f 100644 --- a/vlib/v/checker/tests/incorrect_name_const.vv +++ b/vlib/v/checker/tests/incorrect_name_const.vv @@ -1,3 +1 @@ -const ( - _my_const = 0 -) +const _my_const = 0 diff --git a/vlib/v/checker/tests/lock_const.out b/vlib/v/checker/tests/lock_const.out index 2b923daad..caa80884a 100644 --- a/vlib/v/checker/tests/lock_const.out +++ b/vlib/v/checker/tests/lock_const.out @@ -1,7 +1,7 @@ -vlib/v/checker/tests/lock_const.vv:7:8: error: `a` must be declared as `shared` variable to be locked - 5 | fn main() { - 6 | mut c := 0 - 7 | rlock a { +vlib/v/checker/tests/lock_const.vv:5:8: error: `a` must be declared as `shared` variable to be locked + 3 | fn main() { + 4 | mut c := 0 + 5 | rlock a { | ^ - 8 | c = a - 9 | } + 6 | c = a + 7 | } diff --git a/vlib/v/checker/tests/lock_const.vv b/vlib/v/checker/tests/lock_const.vv index df16a6afe..43592101c 100644 --- a/vlib/v/checker/tests/lock_const.vv +++ b/vlib/v/checker/tests/lock_const.vv @@ -1,6 +1,4 @@ -const ( - a = 5 -) +const a = 5 fn main() { mut c := 0 diff --git a/vlib/v/checker/tests/match_cast_cond_not_same_range_cast_type_err.out b/vlib/v/checker/tests/match_cast_cond_not_same_range_cast_type_err.out index d13770e00..beb5a4b70 100644 --- a/vlib/v/checker/tests/match_cast_cond_not_same_range_cast_type_err.out +++ b/vlib/v/checker/tests/match_cast_cond_not_same_range_cast_type_err.out @@ -1,10 +1,10 @@ -vlib/v/checker/tests/match_cast_cond_not_same_range_cast_type_err.vv:7:2: error: the range type and the match condition type should match - 5 | c := u8(3) - 6 | match c { - 7 | a...b { println('1...5') } +vlib/v/checker/tests/match_cast_cond_not_same_range_cast_type_err.vv:6:2: error: the range type and the match condition type should match + 4 | c := u8(3) + 5 | match c { + 6 | a...b { println('1...5') } | ~~~~~ - 8 | else { println('not 1...5') } - 9 | } + 7 | else { println('not 1...5') } + 8 | } Details: match condition type: u8 range type: u16 diff --git a/vlib/v/checker/tests/match_cast_cond_not_same_range_cast_type_err.vv b/vlib/v/checker/tests/match_cast_cond_not_same_range_cast_type_err.vv index f6a9364e6..51f8e1fb5 100644 --- a/vlib/v/checker/tests/match_cast_cond_not_same_range_cast_type_err.vv +++ b/vlib/v/checker/tests/match_cast_cond_not_same_range_cast_type_err.vv @@ -1,7 +1,6 @@ -const ( - a = u16(1) - b = u16(5) -) +const a = u16(1) +const b = u16(5) + c := u8(3) match c { a...b { println('1...5') } diff --git a/vlib/v/checker/tests/match_ranges_not_same_cast_err.out b/vlib/v/checker/tests/match_ranges_not_same_cast_err.out index 874d0c274..792b6a315 100644 --- a/vlib/v/checker/tests/match_ranges_not_same_cast_err.out +++ b/vlib/v/checker/tests/match_ranges_not_same_cast_err.out @@ -1,10 +1,10 @@ -vlib/v/checker/tests/match_ranges_not_same_cast_err.vv:7:2: error: the low and high parts of a range expression, should have matching types - 5 | c := u16(3) - 6 | match c { - 7 | a...b { println('1...5') } +vlib/v/checker/tests/match_ranges_not_same_cast_err.vv:6:2: error: the low and high parts of a range expression, should have matching types + 4 | c := u16(3) + 5 | match c { + 6 | a...b { println('1...5') } | ~~~~~ - 8 | else { println('not 1...5') } - 9 | } + 7 | else { println('not 1...5') } + 8 | } Details: low part type: u16 high part type: u8 diff --git a/vlib/v/checker/tests/match_ranges_not_same_cast_err.vv b/vlib/v/checker/tests/match_ranges_not_same_cast_err.vv index 16b98b182..84a5326e8 100644 --- a/vlib/v/checker/tests/match_ranges_not_same_cast_err.vv +++ b/vlib/v/checker/tests/match_ranges_not_same_cast_err.vv @@ -1,7 +1,6 @@ -const ( - a = u16(1) - b = u8(5) -) +const a = u16(1) +const b = u8(5) + c := u16(3) match c { a...b { println('1...5') } diff --git a/vlib/v/checker/tests/multi_const_field_name_duplicate_err.out b/vlib/v/checker/tests/multi_const_field_name_duplicate_err.out index 731b9f738..838d46b51 100644 --- a/vlib/v/checker/tests/multi_const_field_name_duplicate_err.out +++ b/vlib/v/checker/tests/multi_const_field_name_duplicate_err.out @@ -1,6 +1,6 @@ -vlib/v/checker/tests/multi_const_field_name_duplicate_err.vv:2:8: error: duplicate const `aaa` - 1 | const (aaa = 1) - 2 | const (aaa = 2) - | ~~~ - 3 | fn main() { - 4 | println(aaa) +vlib/v/checker/tests/multi_const_field_name_duplicate_err.vv:2:7: error: duplicate const `aaa` + 1 | const aaa = 1 + 2 | const aaa = 2 + | ~~~ + 3 | + 4 | fn main() { diff --git a/vlib/v/checker/tests/multi_const_field_name_duplicate_err.vv b/vlib/v/checker/tests/multi_const_field_name_duplicate_err.vv index 883abac8b..e7187f51a 100644 --- a/vlib/v/checker/tests/multi_const_field_name_duplicate_err.vv +++ b/vlib/v/checker/tests/multi_const_field_name_duplicate_err.vv @@ -1,5 +1,6 @@ -const (aaa = 1) -const (aaa = 2) +const aaa = 1 +const aaa = 2 + fn main() { println(aaa) } diff --git a/vlib/v/checker/tests/option_fn_err.out b/vlib/v/checker/tests/option_fn_err.out index 568166f9b..3de24bd37 100644 --- a/vlib/v/checker/tests/option_fn_err.out +++ b/vlib/v/checker/tests/option_fn_err.out @@ -1,126 +1,126 @@ -vlib/v/checker/tests/option_fn_err.vv:34:16: error: cannot use `?int` as `int`, it must be unwrapped first in argument 1 to `twice` - 32 | foo() - 33 | _ := bar(0) - 34 | println(twice(bar(0))) +vlib/v/checker/tests/option_fn_err.vv:32:16: error: cannot use `?int` as `int`, it must be unwrapped first in argument 1 to `twice` + 30 | foo() + 31 | _ := bar(0) + 32 | println(twice(bar(0))) | ~~~~~~ - 35 | - 36 | // anon fn -vlib/v/checker/tests/option_fn_err.vv:37:16: error: cannot use `?int` as `int`, it must be unwrapped first in argument 1 to `anon` - 35 | - 36 | // anon fn - 37 | fn (_ int) {}(bar(0)) + 33 | + 34 | // anon fn +vlib/v/checker/tests/option_fn_err.vv:35:16: error: cannot use `?int` as `int`, it must be unwrapped first in argument 1 to `anon` + 33 | + 34 | // anon fn + 35 | fn (_ int) {}(bar(0)) | ~~~~~~ - 38 | - 39 | // assert -vlib/v/checker/tests/option_fn_err.vv:40:9: error: assert can be used only with `bool` expressions, but found `bool` instead - 38 | - 39 | // assert - 40 | assert bar(true) + 36 | + 37 | // assert +vlib/v/checker/tests/option_fn_err.vv:38:9: error: assert can be used only with `bool` expressions, but found `bool` instead + 36 | + 37 | // assert + 38 | assert bar(true) | ~~~~~~~~~ - 41 | - 42 | // struct -vlib/v/checker/tests/option_fn_err.vv:45:3: error: cannot assign an Option value to a non-option struct field - 43 | mut v := Data{ - 44 | f: fn (_ int) {} - 45 | value: bar(0) + 39 | + 40 | // struct +vlib/v/checker/tests/option_fn_err.vv:43:3: error: cannot assign an Option value to a non-option struct field + 41 | mut v := Data{ + 42 | f: fn (_ int) {} + 43 | value: bar(0) | ~~~~~~~~~~~~~ - 46 | opt: bar(0) - 47 | } -vlib/v/checker/tests/option_fn_err.vv:48:8: error: cannot use `?int` as `int`, it must be unwrapped first in argument 1 to `Data.add` - 46 | opt: bar(0) - 47 | } - 48 | v.add(bar(0)) // call method + 44 | opt: bar(0) + 45 | } +vlib/v/checker/tests/option_fn_err.vv:46:8: error: cannot use `?int` as `int`, it must be unwrapped first in argument 1 to `Data.add` + 44 | opt: bar(0) + 45 | } + 46 | v.add(bar(0)) // call method | ~~~~~~ - 49 | v.f(bar(0)) // call fn field - 50 | -vlib/v/checker/tests/option_fn_err.vv:49:6: error: cannot use `?int` as `int`, it must be unwrapped first in argument 1 to `Data.f` - 47 | } - 48 | v.add(bar(0)) // call method - 49 | v.f(bar(0)) // call fn field + 47 | v.f(bar(0)) // call fn field + 48 | +vlib/v/checker/tests/option_fn_err.vv:47:6: error: cannot use `?int` as `int`, it must be unwrapped first in argument 1 to `Data.f` + 45 | } + 46 | v.add(bar(0)) // call method + 47 | v.f(bar(0)) // call fn field | ~~~~~~ - 50 | - 51 | // array -vlib/v/checker/tests/option_fn_err.vv:53:6: error: unwrapped Option cannot be used in an infix expression - 51 | // array - 52 | mut arr := [1, 2] - 53 | arr << bar(0) + 48 | + 49 | // array +vlib/v/checker/tests/option_fn_err.vv:51:6: error: unwrapped Option cannot be used in an infix expression + 49 | // array + 50 | mut arr := [1, 2] + 51 | arr << bar(0) | ~~ - 54 | // init - 55 | _ := [bar(0)] -vlib/v/checker/tests/option_fn_err.vv:56:27: error: cannot use unwrapped Option as initializer - 54 | // init - 55 | _ := [bar(0)] - 56 | _ := []int{len: 1, init: bar(0)} + 52 | // init + 53 | _ := [bar(0)] +vlib/v/checker/tests/option_fn_err.vv:54:27: error: cannot use unwrapped Option as initializer + 52 | // init + 53 | _ := [bar(0)] + 54 | _ := []int{len: 1, init: bar(0)} | ~~~~~~ - 57 | _ := [bar(0)]! - 58 | _ := [1]int{init: bar(0)} -vlib/v/checker/tests/option_fn_err.vv:58:20: error: cannot use unwrapped Option as initializer - 56 | _ := []int{len: 1, init: bar(0)} - 57 | _ := [bar(0)]! - 58 | _ := [1]int{init: bar(0)} + 55 | _ := [bar(0)]! + 56 | _ := [1]int{init: bar(0)} +vlib/v/checker/tests/option_fn_err.vv:56:20: error: cannot use unwrapped Option as initializer + 54 | _ := []int{len: 1, init: bar(0)} + 55 | _ := [bar(0)]! + 56 | _ := [1]int{init: bar(0)} | ~~~~~~ - 59 | // index - 60 | println(arr[bar(0)]) -vlib/v/checker/tests/option_fn_err.vv:60:13: error: cannot use Option or Result as index (array type `[]int`) - 58 | _ := [1]int{init: bar(0)} - 59 | // index - 60 | println(arr[bar(0)]) + 57 | // index + 58 | println(arr[bar(0)]) +vlib/v/checker/tests/option_fn_err.vv:58:13: error: cannot use Option or Result as index (array type `[]int`) + 56 | _ := [1]int{init: bar(0)} + 57 | // index + 58 | println(arr[bar(0)]) | ~~~~~~~~ - 61 | // array builtin methods - 62 | arr.insert(0, bar(0)) -vlib/v/checker/tests/option_fn_err.vv:62:16: error: cannot use `?int` as `voidptr`, it must be unwrapped first in argument 2 to `[]int.insert` - 60 | println(arr[bar(0)]) - 61 | // array builtin methods - 62 | arr.insert(0, bar(0)) + 59 | // array builtin methods + 60 | arr.insert(0, bar(0)) +vlib/v/checker/tests/option_fn_err.vv:60:16: error: cannot use `?int` as `voidptr`, it must be unwrapped first in argument 2 to `[]int.insert` + 58 | println(arr[bar(0)]) + 59 | // array builtin methods + 60 | arr.insert(0, bar(0)) | ~~~~~~ - 63 | arr.prepend(bar(0)) - 64 | arr.contains(bar(0)) -vlib/v/checker/tests/option_fn_err.vv:63:14: error: cannot use `?int` as `voidptr`, it must be unwrapped first in argument 1 to `[]int.prepend` - 61 | // array builtin methods - 62 | arr.insert(0, bar(0)) - 63 | arr.prepend(bar(0)) + 61 | arr.prepend(bar(0)) + 62 | arr.contains(bar(0)) +vlib/v/checker/tests/option_fn_err.vv:61:14: error: cannot use `?int` as `voidptr`, it must be unwrapped first in argument 1 to `[]int.prepend` + 59 | // array builtin methods + 60 | arr.insert(0, bar(0)) + 61 | arr.prepend(bar(0)) | ~~~~~~ - 64 | arr.contains(bar(0)) - 65 | arr.index(bar(0)) -vlib/v/checker/tests/option_fn_err.vv:64:15: error: cannot use `?int` as `int`, it must be unwrapped first in argument 1 to `.contains()` - 62 | arr.insert(0, bar(0)) - 63 | arr.prepend(bar(0)) - 64 | arr.contains(bar(0)) + 62 | arr.contains(bar(0)) + 63 | arr.index(bar(0)) +vlib/v/checker/tests/option_fn_err.vv:62:15: error: cannot use `?int` as `int`, it must be unwrapped first in argument 1 to `.contains()` + 60 | arr.insert(0, bar(0)) + 61 | arr.prepend(bar(0)) + 62 | arr.contains(bar(0)) | ~~~~~~ - 65 | arr.index(bar(0)) - 66 | println(arr.map(bar(0))) -vlib/v/checker/tests/option_fn_err.vv:65:12: error: cannot use `?int` as `int`, it must be unwrapped first in argument 1 to `.index()` - 63 | arr.prepend(bar(0)) - 64 | arr.contains(bar(0)) - 65 | arr.index(bar(0)) + 63 | arr.index(bar(0)) + 64 | println(arr.map(bar(0))) +vlib/v/checker/tests/option_fn_err.vv:63:12: error: cannot use `?int` as `int`, it must be unwrapped first in argument 1 to `.index()` + 61 | arr.prepend(bar(0)) + 62 | arr.contains(bar(0)) + 63 | arr.index(bar(0)) | ~~~~~~ - 66 | println(arr.map(bar(0))) - 67 | println(arr.filter(bar(true))) -vlib/v/checker/tests/option_fn_err.vv:67:21: error: type mismatch, `bar` must return a bool - 65 | arr.index(bar(0)) - 66 | println(arr.map(bar(0))) - 67 | println(arr.filter(bar(true))) + 64 | println(arr.map(bar(0))) + 65 | println(arr.filter(bar(true))) +vlib/v/checker/tests/option_fn_err.vv:65:21: error: type mismatch, `bar` must return a bool + 63 | arr.index(bar(0)) + 64 | println(arr.map(bar(0))) + 65 | println(arr.filter(bar(true))) | ~~~~~~~~~ - 68 | println(arr.any(bar(true))) - 69 | println(arr.all(bar(true))) -vlib/v/checker/tests/option_fn_err.vv:68:18: error: type mismatch, `bar` must return a bool - 66 | println(arr.map(bar(0))) - 67 | println(arr.filter(bar(true))) - 68 | println(arr.any(bar(true))) + 66 | println(arr.any(bar(true))) + 67 | println(arr.all(bar(true))) +vlib/v/checker/tests/option_fn_err.vv:66:18: error: type mismatch, `bar` must return a bool + 64 | println(arr.map(bar(0))) + 65 | println(arr.filter(bar(true))) + 66 | println(arr.any(bar(true))) | ~~~~~~~~~ - 69 | println(arr.all(bar(true))) - 70 | -vlib/v/checker/tests/option_fn_err.vv:69:18: error: type mismatch, `bar` must return a bool - 67 | println(arr.filter(bar(true))) - 68 | println(arr.any(bar(true))) - 69 | println(arr.all(bar(true))) + 67 | println(arr.all(bar(true))) + 68 | +vlib/v/checker/tests/option_fn_err.vv:67:18: error: type mismatch, `bar` must return a bool + 65 | println(arr.filter(bar(true))) + 66 | println(arr.any(bar(true))) + 67 | println(arr.all(bar(true))) | ~~~~~~~~~ - 70 | - 71 | match bar(0) { -vlib/v/checker/tests/option_fn_err.vv:72:3: error: `match` expression with Option type only checks against `none`, to match its value you must unwrap it first `var?` - 70 | - 71 | match bar(0) { - 72 | 0 {} + 68 | + 69 | match bar(0) { +vlib/v/checker/tests/option_fn_err.vv:70:3: error: `match` expression with Option type only checks against `none`, to match its value you must unwrap it first `var?` + 68 | + 69 | match bar(0) { + 70 | 0 {} | ^ - 73 | else {} - 74 | } + 71 | else {} + 72 | } diff --git a/vlib/v/checker/tests/option_fn_err.vv b/vlib/v/checker/tests/option_fn_err.vv index 51469e617..a1689a09d 100644 --- a/vlib/v/checker/tests/option_fn_err.vv +++ b/vlib/v/checker/tests/option_fn_err.vv @@ -8,9 +8,7 @@ fn bar[T](v T) ?T { return none } -const ( - const_value = bar(0) -) +const const_value = bar(0) struct Data { f fn (int) = unsafe { nil } diff --git a/vlib/v/checker/tests/orm_limit_less_than_zero_error.out b/vlib/v/checker/tests/orm_limit_less_than_zero_error.out index a857371bd..2d595ea32 100644 --- a/vlib/v/checker/tests/orm_limit_less_than_zero_error.out +++ b/vlib/v/checker/tests/orm_limit_less_than_zero_error.out @@ -1,7 +1,7 @@ -vlib/v/checker/tests/orm_limit_less_than_zero_error.vv:18:26: error: ORM: `limit` must be greater than or equal to zero - 16 | - 17 | users := sql db { - 18 | select from User limit user_limit +vlib/v/checker/tests/orm_limit_less_than_zero_error.vv:16:26: error: ORM: `limit` must be greater than or equal to zero + 14 | + 15 | users := sql db { + 16 | select from User limit user_limit | ~~~~~~~~~~ - 19 | }! - 20 | + 17 | }! + 18 | diff --git a/vlib/v/checker/tests/orm_limit_less_than_zero_error.vv b/vlib/v/checker/tests/orm_limit_less_than_zero_error.vv index 753361f37..dc84deca7 100644 --- a/vlib/v/checker/tests/orm_limit_less_than_zero_error.vv +++ b/vlib/v/checker/tests/orm_limit_less_than_zero_error.vv @@ -2,12 +2,10 @@ module main import db.sqlite -const ( - user_limit = -10 -) +const user_limit = -10 struct User { - id int @[primary; sql: serial] + id int @[primary; sql: serial] username string } diff --git a/vlib/v/checker/tests/reserved_type_name_const_err.out b/vlib/v/checker/tests/reserved_type_name_const_err.out index e68e0414e..a4ef2dc8a 100644 --- a/vlib/v/checker/tests/reserved_type_name_const_err.out +++ b/vlib/v/checker/tests/reserved_type_name_const_err.out @@ -2,10 +2,9 @@ vlib/v/checker/tests/reserved_type_name_const_err.vv:1:7: error: invalid use of 1 | const int = 3 | ~~~~~~~ 2 | - 3 | const ( -vlib/v/checker/tests/reserved_type_name_const_err.vv:4:2: error: invalid use of reserved type `f64` as a const name + 3 | const f64 = 'string' +vlib/v/checker/tests/reserved_type_name_const_err.vv:3:7: error: invalid use of reserved type `f64` as a const name + 1 | const int = 3 2 | - 3 | const ( - 4 | f64 = 'string' - | ~~~~~~~~~~~~~~ - 5 | ) + 3 | const f64 = 'string' + | ~~~~~~~~~~~~~~ diff --git a/vlib/v/checker/tests/reserved_type_name_const_err.vv b/vlib/v/checker/tests/reserved_type_name_const_err.vv index 7ff4b58b3..cb2fd6b1f 100644 --- a/vlib/v/checker/tests/reserved_type_name_const_err.vv +++ b/vlib/v/checker/tests/reserved_type_name_const_err.vv @@ -1,5 +1,3 @@ const int = 3 -const ( - f64 = 'string' -) +const f64 = 'string' diff --git a/vlib/v/checker/tests/var_eval_not_used.out b/vlib/v/checker/tests/var_eval_not_used.out index 2cb35938b..6ddaa4fb6 100644 --- a/vlib/v/checker/tests/var_eval_not_used.out +++ b/vlib/v/checker/tests/var_eval_not_used.out @@ -1,6 +1,6 @@ -vlib/v/checker/tests/var_eval_not_used.vv:6:2: error: `c` evaluated but not used - 4 | - 5 | fn main() { - 6 | c +vlib/v/checker/tests/var_eval_not_used.vv:4:2: error: `c` evaluated but not used + 2 | + 3 | fn main() { + 4 | c | ^ - 7 | } + 5 | } diff --git a/vlib/v/checker/tests/var_eval_not_used.vv b/vlib/v/checker/tests/var_eval_not_used.vv index 57642a1f7..bfe4b49b3 100644 --- a/vlib/v/checker/tests/var_eval_not_used.vv +++ b/vlib/v/checker/tests/var_eval_not_used.vv @@ -1,6 +1,4 @@ -const ( - c = 1 -) +const c = 1 fn main() { c diff --git a/vlib/v/checker/tests/var_eval_not_used_scope.out b/vlib/v/checker/tests/var_eval_not_used_scope.out index 89c4afd48..1f8e52ca4 100644 --- a/vlib/v/checker/tests/var_eval_not_used_scope.out +++ b/vlib/v/checker/tests/var_eval_not_used_scope.out @@ -1,7 +1,7 @@ -vlib/v/checker/tests/var_eval_not_used_scope.vv:7:3: error: `c` evaluated but not used - 5 | fn main() { - 6 | { - 7 | c +vlib/v/checker/tests/var_eval_not_used_scope.vv:5:3: error: `c` evaluated but not used + 3 | fn main() { + 4 | { + 5 | c | ^ - 8 | } - 9 | } + 6 | } + 7 | } diff --git a/vlib/v/checker/tests/var_eval_not_used_scope.vv b/vlib/v/checker/tests/var_eval_not_used_scope.vv index 298e35b25..b18df26ca 100644 --- a/vlib/v/checker/tests/var_eval_not_used_scope.vv +++ b/vlib/v/checker/tests/var_eval_not_used_scope.vv @@ -1,6 +1,4 @@ -const ( - c = 1 -) +const c = 1 fn main() { { diff --git a/vlib/v/slow_tests/inout/printing_const_array.vv b/vlib/v/slow_tests/inout/printing_const_array.vv index d6761584d..54c526d5b 100644 --- a/vlib/v/slow_tests/inout/printing_const_array.vv +++ b/vlib/v/slow_tests/inout/printing_const_array.vv @@ -1,8 +1,6 @@ -const ( - dat = 'Data tag ,No data'.split(',') - dd = []Info{len: 4, init: Info{if index in tag { dat[0] + index.str() } else { dat[1] }}} - tag = [1, 2] -) +const dat = 'Data tag ,No data'.split(',') +const dd = []Info{len: 4, init: Info{if index in tag { dat[0] + index.str() } else { dat[1] }}} +const tag = [1, 2] struct Info { val string diff --git a/vlib/v2/gen/v/gen.v b/vlib/v2/gen/v/gen.v index cc643d2b5..80dfe2200 100644 --- a/vlib/v2/gen/v/gen.v +++ b/vlib/v2/gen/v/gen.v @@ -107,19 +107,16 @@ fn (mut g Gen) stmt(stmt ast.Stmt) { g.writeln('}') } ast.ConstDecl { - if stmt.is_public { - g.write('pub ') - } - g.writeln('const (') - g.indent++ for field in stmt.fields { + if stmt.is_public { + g.write('pub ') + } + g.writeln('const ') g.write(field.name) g.write(' = ') g.expr(field.value) g.writeln('') } - g.indent-- - g.writeln(')') } ast.ComptimeStmt { g.write('$') diff --git a/vlib/vweb/csrf/README.md b/vlib/vweb/csrf/README.md index 7d3b76e2d..6495c5d80 100644 --- a/vlib/vweb/csrf/README.md +++ b/vlib/vweb/csrf/README.md @@ -88,15 +88,14 @@ import net.http import vweb import vweb.csrf -const ( - // the configuration moved here - csrf_config = csrf.CsrfConfig{ - // change the secret - secret: 'my-64bytes-secret' - // change to which domains you want to allow - allowed_hosts: ['*'] - } -) +// the configuration moved here +const csrf_config = csrf.CsrfConfig{ + // change the secret + secret: 'my-64bytes-secret' + // change to which domains you want to allow + allowed_hosts: ['*'] +} + struct App { vweb.Context -- 2.39.5