Improve mutability checking. Closes #118.

This commit is contained in:
Graydon Hoare 2010-07-23 15:29:17 -07:00
parent 8bd8413906
commit 44e2dc2789
9 changed files with 60 additions and 15 deletions

View file

@ -1,6 +1,6 @@
// -*- rust -*-
// error-pattern: writing to non-mutable slot
// error-pattern: writing to immutable type
type point = rec(int x, int y, int z);

View file

@ -0,0 +1,8 @@
// error-pattern: writing to immutable type
obj objy(int x) {
fn foo() -> () {
x = 5;
}
}
fn main() {
}

View file

@ -0,0 +1,5 @@
// error-pattern: writing to immutable type
fn main() {
let rec(int x) r = rec(x=1);
r.x = 6;
}

View file

@ -0,0 +1,5 @@
// error-pattern: writing to immutable type
fn main() {
let tup(int) t = tup(1);
t._0 = 5;
}

View file

@ -0,0 +1,5 @@
// error-pattern: writing to immutable type
fn main() {
let vec[int] v = vec(1, 2, 3);
v.(1) = 4;
}

View file

@ -14,7 +14,8 @@ iter range(int start, int stop) -> int {
}
fn main() {
let vec[int] a = vec(-1, -1, -1, -1, -1, -1, -1, -1);
let vec[mutable int] a =
vec[mutable](-1, -1, -1, -1, -1, -1, -1, -1);
let int p = 0;
for each (int i in two()) {

View file

@ -6,7 +6,7 @@ iter two() -> int {
}
fn main() {
let vec[int] a = vec(-1, -1, -1, -1);
let vec[mutable int] a = vec[mutable](-1, -1, -1, -1);
let int p = 0;
for each (int i in two()) {