Skip to content

Commit a67bfeb

Browse files
authored
vrepl: fix output of the fn call (related #21792) (#21800)
1 parent 96eada1 commit a67bfeb

File tree

6 files changed

+25
-6
lines changed

6 files changed

+25
-6
lines changed

cmd/tools/vrepl.v

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,18 @@ fn run_repl(workdir string, vrepl_prefix string) int {
435435
if s.output.len > r.last_output.len {
436436
cur_line_output := s.output[r.last_output.len..]
437437
print_output(cur_line_output)
438+
if s.exit_code == 0 {
439+
r.last_output = s.output.clone()
440+
r.lines << r.line
441+
}
438442
}
439443
} else {
440444
mut temp_line := r.line
441445
func_call, fntype := r.function_call(r.line)
442446
filter_line := r.line.replace(r.line.find_between("'", "'"), '').replace(r.line.find_between('"',
443447
'"'), '')
444448
mut is_statement := false
445-
if func_call {
446-
is_statement = true
447-
} else if filter_line.count('=') % 2 == 1
449+
if filter_line.count('=') % 2 == 1
448450
&& (filter_line.count('!=') + filter_line.count('>=') + filter_line.count('<=')) == 0 {
449451
is_statement = true
450452
} else {
@@ -467,6 +469,10 @@ fn run_repl(workdir string, vrepl_prefix string) int {
467469
if s.output.len > r.last_output.len {
468470
cur_line_output := s.output[r.last_output.len..]
469471
print_output(cur_line_output)
472+
if s.exit_code == 0 {
473+
r.last_output = s.output.clone()
474+
r.lines << temp_line
475+
}
470476
}
471477
continue
472478
}
@@ -478,6 +484,8 @@ fn run_repl(workdir string, vrepl_prefix string) int {
478484
}
479485
} else if temp_line.starts_with('#include ') {
480486
temp_source_code = '${temp_line}\n' + r.current_source_code(false, false)
487+
} else if temp_line.starts_with('fn') {
488+
temp_source_code = r.current_source_code(false, false)
481489
} else {
482490
temp_source_code = r.current_source_code(true, false) + '\n${temp_line}\n'
483491
}
@@ -490,6 +498,8 @@ fn run_repl(workdir string, vrepl_prefix string) int {
490498
r.parse_import(r.line)
491499
} else if r.line.starts_with('#include ') {
492500
r.includes << r.line
501+
} else if r.line.starts_with('fn ') {
502+
r.functions << r.line
493503
} else {
494504
r.lines << r.line
495505
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
print($tmpl('./tmpl/hello.txt'))
1+
$tmpl('./tmpl/hello.txt')
22
===output===
33
hello

vlib/v/slow_tests/repl/fn_calls.repl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
println(math.sinf(50.0))
1+
math.sinf(50.0)
22
println(1+math.sinf(50.0))
33
fn test() { println('foo') } fn test2(a int) { println(a) }
44
test()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import encoding.hex as z
2-
print(z.decode('AB09CD')!.hex())
2+
z.decode('AB09CD')!.hex()
33
===output===
44
ab09cd

vlib/v/slow_tests/repl/method_call.repl renamed to vlib/v/slow_tests/repl/method_call1.repl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ values.pop()
44
values
55
===output===
66
[1, 2, 3]
7+
3
78
[1, 2]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
mut values := [1, 2, 3]
2+
values
3+
println(values.pop())
4+
values
5+
===output===
6+
[1, 2, 3]
7+
3
8+
[1, 2]

0 commit comments

Comments
 (0)