1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

scanner: guarantee an early exit when the parser/scanner is stuck

This commit is contained in:
Delyan Angelov
2020-11-27 12:44:25 +02:00
parent 413d14f53e
commit e6116c47be
3 changed files with 22 additions and 1 deletions

View File

@@ -59,6 +59,7 @@ pub fn compile(command string, pref &pref.Preferences) {
if pref.is_stats {
println('compilation took: ${util.bold(sw.elapsed().milliseconds().str())} ms')
}
b.exit_on_invalid_syntax()
// running does not require the parsers anymore
unsafe {b.myfree()}
if pref.is_test || pref.is_run {
@@ -74,6 +75,21 @@ fn (mut b Builder) myfree() {
unsafe {b.parsed_files.free()}
}
fn (b &Builder) exit_on_invalid_syntax() {
// V should exit with an exit code of 1, when there are errors,
// even when -silent is passed in combination to -check-syntax:
if b.pref.only_check_syntax {
for pf in b.parsed_files {
if pf.errors.len > 0 {
exit(1)
}
}
if b.checker.nr_errors > 0 {
exit(1)
}
}
}
fn (mut b Builder) run_compiled_executable_and_exit() {
if b.pref.skip_running {
return