Port more resource tests to classes

This commit is contained in:
Tim Chevalier 2012-06-01 20:21:59 -07:00
parent 14e3fdea9c
commit 6e2aa3b998
8 changed files with 38 additions and 22 deletions

View File

@ -1,12 +1,12 @@
// test that autoderef of a type like this does not
// cause compiler to loop. Note that no instances
// of such a type could ever be constructed.
resource t(x: x) {} //! ERROR this type cannot be instantiated
enum x = @t; //! ERROR this type cannot be instantiated
fn new_t(x: t) {
x.to_str; //! ERROR attempted access of field to_str
class t { //! ERROR this type cannot be instantiated
let x: x;
let to_str: ();
new(x: x) { self.x = x; self.to_str = (); }
}
enum x = @t; //! ERROR this type cannot be instantiated
fn main() {
}

View File

@ -2,8 +2,17 @@
fn foo<T: const>(_x: T) { }
resource r(_x: int) {}
resource r2(_x: @mut int) {}
class r {
let x:int;
new(x:int) { self.x = x; }
drop {}
}
class r2 {
let x:@mut int;
new(x:@mut int) { self.x = x; }
drop {}
}
fn main() {
foo({f: 3});

View File

@ -1,7 +1,9 @@
// error-pattern: copying a noncopyable value
resource r(i: @mut int) {
*i = *i + 1;
class r {
let i: @mut int;
new(i: @mut int) { self.i = i; }
drop { *(self.i) = *(self.i) + 1; }
}
fn main() {

View File

@ -1,7 +1,9 @@
// error-pattern: copying a noncopyable value
resource my_resource(x: int) {
log(error, x);
class my_resource {
let x: int;
new(x: int) { self.x = x; }
drop { log(error, self.x); }
}
fn main() {

View File

@ -5,7 +5,6 @@
enum an_enum/& { }
iface an_iface/& { }
class a_class/& { new() { } }
resource a_rsrc/&(_x: ()) { }
fn a_fn1(e: an_enum/&a) -> an_enum/&b {
ret e; //! ERROR mismatched types: expected `an_enum/&b` but found `an_enum/&a`
@ -19,11 +18,7 @@ fn a_fn3(e: a_class/&a) -> a_class/&b {
ret e; //! ERROR mismatched types: expected `a_class/&b` but found `a_class/&a`
}
fn a_fn4(e: a_rsrc/&a) -> a_rsrc/&b {
ret e; //! ERROR mismatched types: expected `a_rsrc/&b` but found `a_rsrc/&a`
}
fn a_fn5(e: int/&a) -> int/&b {
fn a_fn4(e: int/&a) -> int/&b {
//!^ ERROR Region parameters are not allowed on this type.
//!^^ ERROR Region parameters are not allowed on this type.
ret e;

View File

@ -1,6 +1,9 @@
// error-pattern: copying a noncopyable value
resource r(b: bool) {
class r {
let b:bool;
new(b: bool) { self.b = b; }
drop {}
}
fn main() {

View File

@ -1,7 +1,9 @@
// error-pattern: copying a noncopyable value
resource r(i: @mut int) {
*i = *i + 1;
class r {
let i: @mut int;
new(i: @mut int) { self.i = i; }
drop { *(self.i) = *(self.i) + 1; }
}
fn f<T>(+i: [T], +j: [T]) {

View File

@ -1,9 +1,12 @@
// error-pattern: copying a noncopyable value
resource r(_i: int) { }
class r {
new(_i:int) {}
drop {}
}
fn main() {
// This can't make sense as it would copy the resources
// This can't make sense as it would copy the classes
let i <- [r(0)];
let j <- [r(1)];
let k = i + j;