Fix tests for new argument-passing convention

This commit is contained in:
Marijn Haverbeke 2011-09-12 10:12:36 +02:00
parent 0e6e56ca60
commit 8b7909afd7
7 changed files with 33 additions and 27 deletions

View File

@ -1,9 +0,0 @@
// error-pattern:expected argument mode
use std;
import std::vec::map;
fn main() {
fn f(i: uint) -> bool { true }
let a = map(f, [5u]);
}

View File

@ -1,8 +0,0 @@
// -*- rust -*-
// error-pattern: mismatched types
fn f(x: &int) { log_err x; }
fn h(x: int) { log_err x; }
fn main() { let g: fn(int) = f; g(10); g = h; g(10); }

View File

@ -1,5 +0,0 @@
// error-pattern:assigning to immutable alias
fn f(i: &int) { i += 2; }
fn main() { f(1); }

View File

@ -1,5 +1,8 @@
// error-pattern:Copying a non-copyable type
// This is still not properly checked
// xfail-test
resource foo(i: int) { }
fn main() { let x <- foo(10); let y = x; }

View File

@ -1,7 +1,12 @@
// error-pattern:may alias with argument
fn foo(x: &int, f: fn()) { log x; }
fn foo(x: &{mutable x: int}, f: fn()) { log x; }
fn whoknows(x: @mutable int) { *x = 10; }
fn whoknows(x: @mutable {mutable x: int}) {
*x = {mutable x: 10};
}
fn main() { let box = @mutable 1; foo(*box, bind whoknows(box)); }
fn main() {
let box = @mutable {mutable x: 1};
foo(*box, bind whoknows(box));
}

View File

@ -1,5 +1,7 @@
// error-pattern:mutable alias to a variable that roots another alias
fn f(a: &int, b: &mutable int) -> int { b += 1; ret a + b; }
fn f(a: &{mutable x: int}, b: &mutable {mutable x: int}) -> int {
b.x += 1; ret a.x + b.x;
}
fn main() { let i = 4; log f(i, i); }
fn main() { let i = {mutable x: 4}; log f(i, i); }

View File

@ -0,0 +1,18 @@
fn f1(a: {mutable x: int}, b: &mutable int, c: -int) -> int {
let r = a.x + b + c;
a.x = 0;
b = 10;
c = 20;
ret r;
}
fn f2(a: int, f: block(x: int)) -> int { f(1); ret a; }
fn main() {
let a = {mutable x: 1}, b = 2, c = 3;
assert (f1(a, b, c) == 6);
assert (a.x == 0);
assert (b == 10);
assert (f2(a.x, {| x | a.x = 50; }) == 0);
assert (a.x == 50);
}