vrepl: fix infix shift operation (#21855)

This commit is contained in:
yuyi 2024-07-13 05:08:52 +08:00 committed by GitHub
parent 790895782d
commit 48ab08c206
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 31 additions and 15 deletions

View file

@ -39,7 +39,6 @@ const repl_folder = os.join_path(os.vtmp_dir(), 'repl')
const possible_statement_patterns = [
'++',
'--',
'<<',
'//',
'/*',
'assert ',
@ -461,20 +460,20 @@ fn run_repl(workdir string, vrepl_prefix string) int {
is_statement = true
}
if !is_statement && (!func_call || fntype == FnType.fn_type) && r.line != '' {
temp_line = 'println(${r.line})'
source_code := r.current_source_code(false, false) + '\n${temp_line}\n'
print_line := 'println(${r.line})'
source_code := r.current_source_code(false, false) + '\n${print_line}\n'
os.write_file(temp_file, source_code) or { panic(err) }
s := repl_run_vfile(temp_file) or { return 1 }
if s.exit_code == 0 {
if s.output.len > r.last_output.len {
cur_line_output := s.output[r.last_output.len..]
print_output(cur_line_output)
if s.exit_code == 0 {
r.last_output = s.output.clone()
r.lines << temp_line
}
r.lines << print_line
}
continue
}
}
mut temp_source_code := ''
if temp_line.starts_with('import ') {
mod := r.line.fields()[1]

View file

@ -7,9 +7,9 @@ error: undefined ident: `a` (use `:=` to declare a variable)
6 |
7 | a = 3
| ^
error: undefined ident: `b`
error: `b` evaluated but not used
5 | import math
6 |
7 | println(b)
7 | b
| ^
[4]

View file

@ -1,7 +1,7 @@
exitasdfasdf
===output===
error: undefined ident: `exitasdfasdf`
error: `exitasdfasdf` evaluated but not used
5 | import math
6 |
7 | println(exitasdfasdf)
7 | exitasdfasdf
| ~~~~~~~~~~~~

View 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