Skip to content

Commit df74f2c

Browse files
jdmbrson
authored andcommitted
Fix error line display slicing.
1 parent 652da4c commit df74f2c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/comp/syntax/codemap.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
8585
// get access to the necessary lines.
8686
auto rdr = ioivec::file_reader(lines.name);
8787
auto file = str::unsafe_from_bytes_ivec(rdr.read_whole_stream());
88-
auto fm = codemap::get_filemap(cm, lines.name);
88+
auto fm = get_filemap(cm, lines.name);
8989

9090
// arbitrarily only print up to six lines of the error
9191
auto max_lines = 6u;
@@ -99,7 +99,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
9999
for (uint line in display_lines) {
100100
ioivec::stdout().write_str(#fmt("%s:%u ", fm.name,
101101
line + 1u));
102-
auto s = codemap::get_line(fm, line as int, file);
102+
auto s = get_line(fm, line as int, file);
103103
if (!str::ends_with(s, "\n")) {
104104
s += "\n";
105105
}
@@ -119,6 +119,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
119119
// If there's one line at fault we can easily point to the problem
120120
if (ivec::len(lines.lines) == 1u) {
121121
auto lo = codemap::lookup_pos(cm, option::get(sp).lo);
122+
auto lo = lookup_pos(cm, option::get(sp).lo);
122123
auto digits = 0u;
123124
auto num = lines.lines.(0) / 10u;
124125

@@ -131,7 +132,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
131132
while (left > 0u) { str::push_char(s, ' '); left -= 1u; }
132133

133134
s += "^";
134-
auto hi = codemap::lookup_pos(cm, option::get(sp).hi);
135+
auto hi = lookup_pos(cm, option::get(sp).hi);
135136
if (hi.col != lo.col) {
136137
// the ^ already takes up one space
137138
auto width = hi.col - lo.col - 1u;
@@ -170,13 +171,14 @@ fn span_to_lines(span sp, codemap::codemap cm) -> @file_lines {
170171
}
171172

172173
fn get_line(filemap fm, int line, &str file) -> str {
174+
let uint begin = fm.lines.(line) - fm.lines.(0);
173175
let uint end;
174176
if ((line as uint) + 1u >= ivec::len(fm.lines)) {
175177
end = str::byte_len(file);
176178
} else {
177-
end = fm.lines.(line + 1);
179+
end = fm.lines.(line + 1) - fm.lines.(0);
178180
}
179-
ret str::slice(file, fm.lines.(line), end);
181+
ret str::slice(file, begin, end);
180182
}
181183

182184
fn get_filemap(codemap cm, str filename) -> filemap {

0 commit comments

Comments
 (0)