repl: fix for-loop/if statement duplicate printing bug

pull/5020/head
Ned Palacios 2020-05-25 16:35:55 +08:00 committed by GitHub
parent 96808a0e2a
commit 3aeaa24df6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -219,6 +219,13 @@ fn run_repl(workdir string, vrepl_prefix string) {
if temp_line.starts_with('import ') || temp_line.starts_with('#include ') {
temp_source_code = '${temp_line}\n' + r.current_source_code(false)
} else {
for i, l in r.lines {
if (l.starts_with('for ') || l.starts_with('if ')) && l.contains('println') {
r.lines.delete(i)
break
}
}
temp_source_code = r.current_source_code(true) + '\n${temp_line}\n'
}
os.write_file(temp_file, temp_source_code)