From 844fe207206b6708f2a7e05214857c92c4b7d28b Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Wed, 27 Apr 2011 14:55:55 -0700 Subject: Fix some nested patterns in rustc In rustc, nested patterns were potentially matching when they shouldn't match, because a loop index wasn't being incremented. Fixed it and added one test case. --- src/comp/middle/trans.rs | 2 ++ src/test/run-pass/nested-pattern.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/test/run-pass/nested-pattern.rs (limited to 'src') diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 75c7aa84..a37308dd 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -3772,6 +3772,8 @@ fn trans_pat_match(@block_ctxt cx, @ast.pat pat, ValueRef llval, auto subpat_res = trans_pat_match(matched_cx, subpat, llsubval, next_cx); matched_cx = subpat_res.bcx; + + i += 1; } } diff --git a/src/test/run-pass/nested-pattern.rs b/src/test/run-pass/nested-pattern.rs new file mode 100644 index 00000000..e59c2dd5 --- /dev/null +++ b/src/test/run-pass/nested-pattern.rs @@ -0,0 +1,29 @@ +// a bug was causing this to complain about leaked memory on exit + +use std; +import std.option; +import std.option.some; +import std.option.none; + +tag t { + foo(int, uint); + bar(int, option.t[int]); +} + +fn nested(t o) { + + alt (o) { + case (bar(?i, some[int](_))) { + log_err "wrong pattern matched"; + fail; + } + case (_) { + log_err "succeeded"; + } + } + +} + +fn main() { + nested (bar (1, none[int])); +} \ No newline at end of file -- cgit v1.2.3