about summary refs log tree commit diff
path: root/src/comp/syntax
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2011-07-13 10:18:40 -0400
committerBrian Anderson <banderson@mozilla.com>2011-07-16 15:56:28 -0700
commitdf74f2cde95e99bd6148dbb59de956871ab4fc8e (patch)
treee24c9295b50f2f03139ed28b92821e2d7fc06627 /src/comp/syntax
parent652da4ca55e5b579570083231a11680e9f889b11 (diff)
downloadrust-df74f2cde95e99bd6148dbb59de956871ab4fc8e.tar.gz
rust-df74f2cde95e99bd6148dbb59de956871ab4fc8e.zip
Fix error line display slicing.
Diffstat (limited to 'src/comp/syntax')
-rw-r--r--src/comp/syntax/codemap.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs
index 92639819aa9..333c8fb8e2f 100644
--- a/src/comp/syntax/codemap.rs
+++ b/src/comp/syntax/codemap.rs
@@ -85,7 +85,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
             //        get access to the necessary lines.
             auto rdr = ioivec::file_reader(lines.name);
             auto file = str::unsafe_from_bytes_ivec(rdr.read_whole_stream());
-            auto fm = codemap::get_filemap(cm, lines.name);
+            auto fm = get_filemap(cm, lines.name);
 
             // arbitrarily only print up to six lines of the error
             auto max_lines = 6u;
@@ -99,7 +99,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
             for (uint line in display_lines) {
                 ioivec::stdout().write_str(#fmt("%s:%u ", fm.name,
                                                 line + 1u));
-                auto s = codemap::get_line(fm, line as int, file);
+                auto s = get_line(fm, line as int, file);
                 if (!str::ends_with(s, "\n")) {
                     s += "\n";
                 }
@@ -119,6 +119,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
             // If there's one line at fault we can easily point to the problem
             if (ivec::len(lines.lines) == 1u) {
                 auto lo = codemap::lookup_pos(cm, option::get(sp).lo);
+                auto lo = lookup_pos(cm, option::get(sp).lo);
                 auto digits = 0u;
                 auto num = lines.lines.(0) / 10u;
 
@@ -131,7 +132,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
                 while (left > 0u) { str::push_char(s, ' '); left -= 1u; }
 
                 s += "^";
-                auto hi = codemap::lookup_pos(cm, option::get(sp).hi);
+                auto hi = lookup_pos(cm, option::get(sp).hi);
                 if (hi.col != lo.col) {
                     // the ^ already takes up one space
                     auto width = hi.col - lo.col - 1u;
@@ -170,13 +171,14 @@ fn span_to_lines(span sp, codemap::codemap cm) -> @file_lines {
 }
 
 fn get_line(filemap fm, int line, &str file) -> str {
+    let uint begin = fm.lines.(line) - fm.lines.(0);
     let uint end;
     if ((line as uint) + 1u >= ivec::len(fm.lines)) {
         end = str::byte_len(file);
     } else {
-        end = fm.lines.(line + 1);
+        end = fm.lines.(line + 1) - fm.lines.(0);
     }
-    ret str::slice(file, fm.lines.(line), end);
+    ret str::slice(file, begin, end);
 }
 
 fn get_filemap(codemap cm, str filename) -> filemap {