Fix vector pattern matching. Closes #6909.

This commit is contained in:
Michael Sullivan 2013-08-08 15:19:19 -07:00
parent 6362c3ad6b
commit fb32ddf1a2
3 changed files with 159 additions and 44 deletions

View file

@ -1,22 +1,22 @@
pub fn main() {
let x = @[1, 2, 3];
match x {
[2, .._] => ::std::util::unreachable(),
[2, .._] => fail!(),
[1, ..tail] => {
assert_eq!(tail, [2, 3]);
}
[_] => ::std::util::unreachable(),
[] => ::std::util::unreachable()
[_] => fail!(),
[] => fail!()
}
let y = (~[(1, true), (2, false)], 0.5);
match y {
([_, _, _], 0.5) => ::std::util::unreachable(),
([_, _, _], 0.5) => fail!(),
([(1, a), (b, false), ..tail], _) => {
assert_eq!(a, true);
assert_eq!(b, 2);
assert!(tail.is_empty());
}
([..tail], _) => ::std::util::unreachable()
([..tail], _) => fail!()
}
}

View file

@ -1,14 +1,14 @@
fn a() {
let x = [1];
match x {
[_, _, _, _, _, .._] => ::std::util::unreachable(),
[.._, _, _, _, _] => ::std::util::unreachable(),
[_, .._, _, _] => ::std::util::unreachable(),
[_, _] => ::std::util::unreachable(),
[_, _, _, _, _, .._] => fail!(),
[.._, _, _, _, _] => fail!(),
[_, .._, _, _] => fail!(),
[_, _] => fail!(),
[a] => {
assert_eq!(a, 1);
}
[] => ::std::util::unreachable()
[] => fail!()
}
}
@ -48,7 +48,28 @@ fn b() {
}
}
fn c() {
let x = [1];
match x {
[2, .. _] => fail!(),
[.. _] => ()
}
}
fn d() {
let x = [1, 2, 3];
let branch = match x {
[1, 1, .. _] => 0,
[1, 2, 3, .. _] => 1,
[1, 2, .. _] => 2,
_ => 3
};
assert_eq!(branch, 1);
}
pub fn main() {
a();
b();
c();
d();
}