diff --git a/src/bin/rhai-dbg.rs b/src/bin/rhai-dbg.rs index cecb2ad5c..72ffe8eab 100644 --- a/src/bin/rhai-dbg.rs +++ b/src/bin/rhai-dbg.rs @@ -84,7 +84,8 @@ fn print_current_source( /// Pretty-print error. fn print_error(input: &str, mut err: EvalAltResult) { - let lines: Vec<_> = input.trim().lines().collect(); + // Do not use `line` because it "eats" the last empty line if the script ends with a newline. + let lines: Vec<_> = input.split('\n').collect(); let pos = err.take_position(); let line_no = if lines.len() > 1 { diff --git a/src/bin/rhai-repl.rs b/src/bin/rhai-repl.rs index 65b826b7b..6a1215c7d 100644 --- a/src/bin/rhai-repl.rs +++ b/src/bin/rhai-repl.rs @@ -11,7 +11,8 @@ const HISTORY_FILE: &str = ".rhai-repl-history"; /// Pretty-print error. fn print_error(input: &str, mut err: EvalAltResult) { - let lines: Vec<_> = input.lines().collect(); + // Do not use `line` because it "eats" the last empty line if the script ends with a newline. + let lines: Vec<_> = input.split('\n').collect(); let pos = err.take_position(); let line_no = if lines.len() > 1 { diff --git a/src/bin/rhai-run.rs b/src/bin/rhai-run.rs index b8503db0f..effd568b0 100644 --- a/src/bin/rhai-run.rs +++ b/src/bin/rhai-run.rs @@ -20,7 +20,8 @@ fn eprint_error(input: &str, mut err: EvalAltResult) { eprintln!(); } - let lines: Vec<_> = input.lines().collect(); + // Do not use `line` because it "eats" the last empty line if the script ends with a newline. + let lines: Vec<_> = input.split('\n').collect(); // Print error let pos = err.take_position();