Skip to content

Commit 51f4d99

Browse files
authored
all: change optional to result in most of the libraries (#16123)
1 parent 0d36856 commit 51f4d99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+439
-446
lines changed

.github/workflows/v_apps_and_modules_compile.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ jobs:
8181
echo "Test libsodium"
8282
VJOBS=1 v test ~/.vmodules/libsodium
8383
84-
- name: Build VEX
85-
run: |
86-
echo "Install Vex"
87-
v install nedpals.vex
88-
echo "Compile all of the Vex examples"
89-
v should-compile-all ~/.vmodules/nedpals/vex/examples
90-
echo "Compile the simple Vex example with -gc boehm -skip-unused"
91-
v -gc boehm -skip-unused ~/.vmodules/nedpals/vex/examples/simple_example.v
92-
echo "Run Vex Tests"
93-
v test ~/.vmodules/nedpals/vex
84+
## - name: Build VEX
85+
## run: |
86+
## echo "Install Vex"
87+
## v install nedpals.vex
88+
## echo "Compile all of the Vex examples"
89+
## v should-compile-all ~/.vmodules/nedpals/vex/examples
90+
## echo "Compile the simple Vex example with -gc boehm -skip-unused"
91+
## v -gc boehm -skip-unused ~/.vmodules/nedpals/vex/examples/simple_example.v
92+
## echo "Run Vex Tests"
93+
## v test ~/.vmodules/nedpals/vex
9494

9595
- name: Build go2v
9696
run: |

cmd/tools/vdoc/tests/vdoc_file_test.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn find_diff_cmd() string {
1616

1717
fn test_vet() {
1818
os.setenv('VCOLORS', 'never', true)
19-
os.chdir(vroot)?
19+
os.chdir(vroot)!
2020
test_dir := 'cmd/tools/vdoc/tests/testdata'
2121
main_files := get_main_files_in_dir(test_dir)
2222
fails := check_path(vexe, test_dir, main_files)

cmd/tools/vdoc/utils.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn set_output_type_from_str(format string) OutputType {
7070
return output_type
7171
}
7272

73-
fn get_ignore_paths(path string) ?[]string {
73+
fn get_ignore_paths(path string) ![]string {
7474
ignore_file_path := os.join_path(path, '.vdocignore')
7575
ignore_content := os.read_file(ignore_file_path) or {
7676
return error_with_code('ignore file not found.', 1)

examples/cli.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn main() {
4141
cmd.parse(os.args)
4242
}
4343

44-
fn greet_func(cmd Command) ? {
44+
fn greet_func(cmd Command) ! {
4545
language := cmd.flags.get_string('language') or { panic('Failed to get `language` flag: $err') }
4646
times := cmd.flags.get_int('times') or { panic('Failed to get `times` flag: $err') }
4747
name := cmd.args[0]
@@ -69,10 +69,10 @@ fn greet_func(cmd Command) ? {
6969
}
7070
}
7171

72-
fn greet_pre_func(cmd Command) ? {
72+
fn greet_pre_func(cmd Command) ! {
7373
println('This is a function running before the main function.\n')
7474
}
7575

76-
fn greet_post_func(cmd Command) ? {
76+
fn greet_post_func(cmd Command) ! {
7777
println('\nThis is a function running after the main function.')
7878
}

examples/vpwgen.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010
for _ in 0 .. repeats {
1111
mut sb := strings.new_builder(blocksize)
1212
for {
13-
x := rand.read(blocksize)?
13+
x := rand.read(blocksize)!
1414
for c in x {
1515
if c >= `0` && c <= `~` {
1616
sb.write_u8(c)

vlib/arrays/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import arrays
99
1010
fn main() {
1111
a := [1, 5, 7, 0, 9]
12-
assert arrays.min(a)? == 0
13-
assert arrays.max(a)? == 9
14-
assert arrays.idx_min(a)? == 3
12+
assert arrays.min(a)! == 0
13+
assert arrays.max(a)! == 9
14+
assert arrays.idx_min(a)! == 3
1515
}
1616
```

vlib/arrays/arrays.v

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub fn window<T>(array []T, attr WindowAttribute) [][]T {
200200
// which means you can only pass array of numbers for now.
201201
// TODO: Fix generic operator overloading detection issue.
202202
// Example: arrays.sum<int>([1, 2, 3, 4, 5])? // => 15
203-
pub fn sum<T>(array []T) ?T {
203+
pub fn sum<T>(array []T) !T {
204204
if array.len == 0 {
205205
return error('Cannot sum up array of nothing.')
206206
} else {
@@ -222,8 +222,8 @@ pub fn sum<T>(array []T) ?T {
222222
// returns the accumulated value in `acc`.
223223
// returns an error if the array is empty.
224224
// See also: [fold](#fold).
225-
// Example: arrays.reduce([1, 2, 3, 4, 5], fn (t1 int, t2 int) int { return t1 * t2 })? // => 120
226-
pub fn reduce<T>(array []T, reduce_op fn (acc T, elem T) T) ?T {
225+
// Example: arrays.reduce([1, 2, 3, 4, 5], fn (t1 int, t2 int) int { return t1 * t2 })! // => 120
226+
pub fn reduce<T>(array []T, reduce_op fn (acc T, elem T) T) !T {
227227
if array.len == 0 {
228228
return error('Cannot reduce array of nothing.')
229229
} else {
@@ -245,7 +245,7 @@ pub fn reduce<T>(array []T, reduce_op fn (acc T, elem T) T) ?T {
245245
// returns the accumulated value in `acc`.
246246
// returns an error if the array is empty.
247247
// See also: [fold_indexed](#fold_indexed).
248-
pub fn reduce_indexed<T>(array []T, reduce_op fn (idx int, acc T, elem T) T) ?T {
248+
pub fn reduce_indexed<T>(array []T, reduce_op fn (idx int, acc T, elem T) T) !T {
249249
if array.len == 0 {
250250
return error('Cannot reduce array of nothing.')
251251
} else {
@@ -427,8 +427,8 @@ pub fn lower_bound<T>(array []T, val T) !T {
427427
}
428428

429429
// returns the largest element <= val, requires `array` to be sorted
430-
// Example: arrays.upper_bound([2, 4, 6, 8], 3)? // => 2
431-
pub fn upper_bound<T>(array []T, val T) ?T {
430+
// Example: arrays.upper_bound([2, 4, 6, 8], 3)! // => 2
431+
pub fn upper_bound<T>(array []T, val T) !T {
432432
if array.len == 0 {
433433
return error('.upper_bound called on an empty array')
434434
}

vlib/arrays/arrays_test.v

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn test_min() {
1414
c := [u8(4), 9, 3, 1]
1515
mut rb := min(c)!
1616
assert rb == u8(1)
17-
rb = min(c[..3])?
17+
rb = min(c[..3])!
1818
assert rb == u8(3)
1919
}
2020

@@ -243,26 +243,26 @@ fn test_concat_string() {
243243

244244
fn test_binary_search() {
245245
a := [1, 3, 3, 4, 5, 6, 7, 8, 10]
246-
assert binary_search(a, 3)? == 1
246+
assert binary_search(a, 3)! == 1
247247
assert (binary_search(a, 0) or { -1 }) == -1
248248
}
249249

250250
fn test_lower_bound() {
251251
a := [1, 3, 3, 4, 5, 6, 7, 8, 10]
252252
b := []int{}
253253
c := [1, 2, 3]
254-
assert lower_bound(a, 2)? == 3
254+
assert lower_bound(a, 2)! == 3
255255
assert (lower_bound(b, 4) or { -1 }) == -1
256-
assert lower_bound(c, 3)? == 3
256+
assert lower_bound(c, 3)! == 3
257257
}
258258

259259
fn test_upper_bound() {
260260
a := [1, 3, 3, 4, 5, 6, 7, 8, 10]
261261
b := []int{}
262262
c := [1, 2, 3]
263-
assert upper_bound(a, 9)? == 8
263+
assert upper_bound(a, 9)! == 8
264264
assert (upper_bound(b, 4) or { -1 }) == -1
265-
assert upper_bound(c, 2)? == 2
265+
assert upper_bound(c, 2)! == 2
266266
}
267267

268268
fn test_rotate_right() {

vlib/cli/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ fn main() {
1818
mut app := cli.Command{
1919
name: 'example-app'
2020
description: 'example-app'
21-
execute: fn (cmd cli.Command) ? {
21+
execute: fn (cmd cli.Command) ! {
2222
println('hello app')
2323
return
2424
}
2525
commands: [
2626
cli.Command{
2727
name: 'sub'
28-
execute: fn (cmd cli.Command) ? {
28+
execute: fn (cmd cli.Command) ! {
2929
println('hello subcommand')
3030
return
3131
}

vlib/cli/command.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module cli
22

33
import term
44

5-
type FnCommandCallback = fn (cmd Command) ?
5+
type FnCommandCallback = fn (cmd Command) !
66

77
// str returns the `string` representation of the callback.
88
pub fn (f FnCommandCallback) str() string {
@@ -311,7 +311,7 @@ pub fn (cmd Command) execute_man() {
311311
}
312312
}
313313

314-
fn (cmds []Command) get(name string) ?Command {
314+
fn (cmds []Command) get(name string) !Command {
315315
for cmd in cmds {
316316
if cmd.name == name {
317317
return cmd

vlib/cli/command_test.v

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn test_if_subcommands_parse_args() {
3030
cmd.parse(['command', 'subcommand', 'arg0', 'arg1'])
3131
}
3232

33-
fn if_subcommands_parse_args_func(cmd cli.Command) ? {
33+
fn if_subcommands_parse_args_func(cmd cli.Command) ! {
3434
assert cmd.name == 'subcommand' && compare_arrays(cmd.args, ['arg0', 'arg1'])
3535
}
3636

@@ -51,8 +51,8 @@ fn test_if_command_has_default_version_subcommand_if_version_is_set() {
5151
assert has_command(cmd, 'version')
5252
}
5353

54-
fn flag_should_be_set(cmd cli.Command) ? {
55-
flag := cmd.flags.get_string('flag')?
54+
fn flag_should_be_set(cmd cli.Command) ! {
55+
flag := cmd.flags.get_string('flag')!
5656
assert flag == 'value'
5757
}
5858

@@ -95,10 +95,10 @@ fn test_if_flag_gets_set_with_long_arg() {
9595
cmd.parse(['command', '--flag', 'value'])
9696
}
9797

98-
fn flag_should_have_value_of_42(cmd cli.Command) ? {
99-
flag := cmd.flags.get_string('flag')?
98+
fn flag_should_have_value_of_42(cmd cli.Command) ! {
99+
flag := cmd.flags.get_string('flag')!
100100
assert flag == 'value'
101-
value := cmd.flags.get_int('value')?
101+
value := cmd.flags.get_int('value')!
102102
assert value == 42
103103
}
104104

@@ -135,7 +135,7 @@ fn test_if_required_flags_get_set() {
135135
cmd.parse(['command', '-flag', 'value', '-value', '42'])
136136
}
137137

138-
fn flag_is_set_in_subcommand(cmd cli.Command) ? {
138+
fn flag_is_set_in_subcommand(cmd cli.Command) ! {
139139
flag := cmd.flags.get_string('flag') or { panic(err) }
140140
assert flag == 'value'
141141
}
@@ -197,7 +197,7 @@ fn test_command_setup() {
197197
}
198198

199199
// helper functions
200-
fn empty_func(cmd cli.Command) ? {
200+
fn empty_func(cmd cli.Command) ! {
201201
}
202202

203203
fn has_command(cmd cli.Command, name string) bool {

0 commit comments

Comments
 (0)