]> git.lizzy.rs Git - rust.git/commitdiff
No, not all fn constraints have the same args as the fn does, in the same order...
authorTim Chevalier <chevalier@alum.wellesley.edu>
Thu, 1 Sep 2011 22:31:48 +0000 (15:31 -0700)
committerTim Chevalier <chevalier@alum.wellesley.edu>
Thu, 1 Sep 2011 22:41:09 +0000 (15:41 -0700)
derp!

Closes #862

src/comp/middle/tstate/auxiliary.rs
src/test/run-pass/bug-862.rs [new file with mode: 0644]

index f12e93bb772752b49bbbaefd3a546ab7ed08f9b6..d4caf9bc03d71889abcd75e93d31fb83a02909dd 100644 (file)
@@ -1048,10 +1048,24 @@ fn do_nothing<T>(_f: &_fn, _tp: &[ty_param], _sp: &span, _i: &fn_ident,
 }
 
 
-fn args_to_constr_args(sp: &span, args: &[arg]) -> [@constr_arg_use] {
+fn args_to_constr_args(tcx: &ty::ctxt, args: &[arg],
+                       indices:&[@sp_constr_arg<uint>]) -> [@constr_arg_use] {
     let actuals: [@constr_arg_use] = [];
-    for a: arg in args {
-        actuals += [@respan(sp, carg_ident({ident: a.ident, node: a.id}))];
+    let num_args = vec::len(args);
+    for a:@sp_constr_arg<uint> in indices {
+        actuals += [@respan(a.span, alt a.node {
+          carg_base. { carg_base }
+          carg_ident(i) {
+            if i < num_args {
+                carg_ident({ident: args[i].ident, node:args[i].id})
+            }
+            else {
+                tcx.sess.span_bug(a.span, ~"Index out of bounds in \
+                  constraint arg");
+            }
+          }
+          carg_lit(l) { carg_lit(l) }
+        })];
     }
     ret actuals;
 }
@@ -1060,7 +1074,7 @@ fn ast_constr_to_ts_constr(tcx: &ty::ctxt, args: &[arg], c: &@constr) ->
    tsconstr {
     let tconstr = ty::ast_constr_to_constr(tcx, c);
     ret npred(tconstr.node.path, tconstr.node.id,
-              args_to_constr_args(tconstr.span, args));
+         args_to_constr_args(tcx, args, tconstr.node.args));
 }
 
 fn ast_constr_to_sp_constr(tcx: &ty::ctxt, args: &[arg], c: &@constr) ->
diff --git a/src/test/run-pass/bug-862.rs b/src/test/run-pass/bug-862.rs
new file mode 100644 (file)
index 0000000..e3cddda
--- /dev/null
@@ -0,0 +1,11 @@
+pure fn p(j: int) -> bool { true }
+
+fn f(i: int, j: int) : p(j) -> int { j }
+
+fn g(i: int, j: int) : p(j) -> int { f(i, j) }
+
+fn main() {
+    let x = 1;
+    check p(x);
+    log g(x, x);
+}
\ No newline at end of file