Enforce mutability declarations in classes; correct shapes for classes
1. Enforce mutability declarations on class fields. Don't allow any mutation of class fields not declared as mutable (except inside the constructor). 2. Handle classes correctly in shape (treat classes like records).
This commit is contained in:
parent
c9102ee7a1
commit
edb747ceed
15 changed files with 187 additions and 40 deletions
15
src/test/compile-fail/mutable-class-fields.rs
Normal file
15
src/test/compile-fail/mutable-class-fields.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
// error-pattern:assigning to immutable field
|
||||
class cat {
|
||||
priv {
|
||||
let mutable meows : uint;
|
||||
}
|
||||
|
||||
let how_hungry : int;
|
||||
|
||||
new(in_x : uint, in_y : int) { meows = in_x; how_hungry = in_y; }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let nyan : cat = cat(52u, 99);
|
||||
nyan.how_hungry = 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue