Fix Issue #1926 by sorting the gather list.

This commit is contained in:
Kevin Atkinson 2012-03-06 18:07:10 -07:00 committed by Niko Matsakis
parent 6f5853f5a1
commit 15985277b9
2 changed files with 12 additions and 1 deletions

View File

@ -103,6 +103,9 @@ fn gather_anti_quotes<N: qq_helper>(lo: uint, node: N) -> aq_ctxt
with *default_visitor()};
let cx = @{lo:lo, mutable gather: []};
node.visit(cx, mk_vt(v));
// FIXME: Maybe this is an overkill (merge_sort), it might be better
// to just keep the gather array in sorted order ...
cx.gather = std::sort::merge_sort({|a,b| a.lo < b.lo}, copy cx.gather);
ret cx;
}
@ -200,9 +203,11 @@ fn finish<T: qq_helper>
let qcx = gather_anti_quotes(sp.lo, node);
let cx = qcx;
// assert that the vector is sorted by position:
uint::range(1u, vec::len(cx.gather)) {|i|
assert cx.gather[i-1u].lo < cx.gather[i].lo;
// ^^ check that the vector is sorted
assert cx.gather[i-1u].hi <= cx.gather[i].lo;
// ^^ check that the spans are non-overlapping
}
let str2 = "";

View File

@ -91,6 +91,12 @@ fn main() {
let crate = #ast(crate) { fn a() { } };
check_pp(crate, pprust::print_crate_, "fn a() { }\n");
// issue #1926
let s = #ast(expr){__s};
let e = #ast(expr){__e};
let call = #ast(expr){$(s).foo {|__e| $(e)}};
check_pp(call, pprust::print_expr, "__s.foo {|__e| __e }")
}
fn check_pp<T>(expr: T, f: fn(pprust::ps, T), expect: str) {