mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
vrepl: fix infix shift operation (#21855)
This commit is contained in:
parent
790895782d
commit
48ab08c206
4 changed files with 31 additions and 15 deletions
|
@ -39,7 +39,6 @@ const repl_folder = os.join_path(os.vtmp_dir(), 'repl')
|
||||||
const possible_statement_patterns = [
|
const possible_statement_patterns = [
|
||||||
'++',
|
'++',
|
||||||
'--',
|
'--',
|
||||||
'<<',
|
|
||||||
'//',
|
'//',
|
||||||
'/*',
|
'/*',
|
||||||
'assert ',
|
'assert ',
|
||||||
|
@ -461,20 +460,20 @@ fn run_repl(workdir string, vrepl_prefix string) int {
|
||||||
is_statement = true
|
is_statement = true
|
||||||
}
|
}
|
||||||
if !is_statement && (!func_call || fntype == FnType.fn_type) && r.line != '' {
|
if !is_statement && (!func_call || fntype == FnType.fn_type) && r.line != '' {
|
||||||
temp_line = 'println(${r.line})'
|
print_line := 'println(${r.line})'
|
||||||
source_code := r.current_source_code(false, false) + '\n${temp_line}\n'
|
source_code := r.current_source_code(false, false) + '\n${print_line}\n'
|
||||||
os.write_file(temp_file, source_code) or { panic(err) }
|
os.write_file(temp_file, source_code) or { panic(err) }
|
||||||
s := repl_run_vfile(temp_file) or { return 1 }
|
s := repl_run_vfile(temp_file) or { return 1 }
|
||||||
|
if s.exit_code == 0 {
|
||||||
if s.output.len > r.last_output.len {
|
if s.output.len > r.last_output.len {
|
||||||
cur_line_output := s.output[r.last_output.len..]
|
cur_line_output := s.output[r.last_output.len..]
|
||||||
print_output(cur_line_output)
|
print_output(cur_line_output)
|
||||||
if s.exit_code == 0 {
|
|
||||||
r.last_output = s.output.clone()
|
r.last_output = s.output.clone()
|
||||||
r.lines << temp_line
|
r.lines << print_line
|
||||||
}
|
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mut temp_source_code := ''
|
mut temp_source_code := ''
|
||||||
if temp_line.starts_with('import ') {
|
if temp_line.starts_with('import ') {
|
||||||
mod := r.line.fields()[1]
|
mod := r.line.fields()[1]
|
||||||
|
|
|
@ -7,9 +7,9 @@ error: undefined ident: `a` (use `:=` to declare a variable)
|
||||||
6 |
|
6 |
|
||||||
7 | a = 3
|
7 | a = 3
|
||||||
| ^
|
| ^
|
||||||
error: undefined ident: `b`
|
error: `b` evaluated but not used
|
||||||
5 | import math
|
5 | import math
|
||||||
6 |
|
6 |
|
||||||
7 | println(b)
|
7 | b
|
||||||
| ^
|
| ^
|
||||||
[4]
|
[4]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
exitasdfasdf
|
exitasdfasdf
|
||||||
===output===
|
===output===
|
||||||
error: undefined ident: `exitasdfasdf`
|
error: `exitasdfasdf` evaluated but not used
|
||||||
5 | import math
|
5 | import math
|
||||||
6 |
|
6 |
|
||||||
7 | println(exitasdfasdf)
|
7 | exitasdfasdf
|
||||||
| ~~~~~~~~~~~~
|
| ~~~~~~~~~~~~
|
||||||
|
|
17
vlib/v/slow_tests/repl/infix_shift_op.repl
Normal file
17
vlib/v/slow_tests/repl/infix_shift_op.repl
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
4 >> 1
|
||||||
|
4 << 1
|
||||||
|
println(4 >> 1)
|
||||||
|
println(4 << 1)
|
||||||
|
typeof(4 >> 1).name
|
||||||
|
typeof(4 << 1).name
|
||||||
|
println(typeof(4 >> 1).name)
|
||||||
|
println(typeof(4 << 1).name)
|
||||||
|
===output===
|
||||||
|
2
|
||||||
|
8
|
||||||
|
2
|
||||||
|
8
|
||||||
|
int literal
|
||||||
|
int literal
|
||||||
|
int literal
|
||||||
|
int literal
|
Loading…
Add table
Add a link
Reference in a new issue