1
Fork 0

Tests for copyability and sendability rules for classes

Closes #2296
This commit is contained in:
Tim Chevalier 2012-06-01 17:48:07 -07:00
parent 11b4a92fc8
commit de40318037
3 changed files with 44 additions and 0 deletions

View file

@ -0,0 +1,16 @@
// error-pattern: copying a noncopyable value
// Test that a class with a non-copyable field can't be
// copied
class bar {
new() {}
drop {}
}
class foo {
let i: int;
let j: bar;
new(i:int) { self.i = i; self.j = bar(); }
}
fn main() { let x <- foo(10); let y = x; log(error, x); }

View file

@ -0,0 +1,15 @@
// Test that a class with an unsendable field can't be
// sent
class foo {
let i: int;
let j: @str;
new(i:int, j: @str) { self.i = i; self.j = j; }
}
fn main() {
let cat = "kitty";
let po = comm::port(); //! ERROR missing `send`
let ch = comm::chan(po); //! ERROR missing `send`
comm::send(ch, foo(42, @cat)); //! ERROR missing `send`
}

View file

@ -0,0 +1,13 @@
// Test that a class with only sendable fields can be sent
class foo {
let i: int;
let j: char;
new(i:int, j: char) { self.i = i; self.j = j; }
}
fn main() {
let po = comm::port::<foo>();
let ch = comm::chan(po);
comm::send(ch, foo(42, 'c'));
}