Logo
Explore Help
Register Sign In
rust-lang/rust
1
0
Fork 0
You've already forked rust
Code Issues Pull Requests Actions 1 Packages Projects Releases Wiki Activity
Files
734494a04dc3be4745c89a1b9d0361c3a45ddfb4
rust/src/test/compile-fail/mutable-class-fields.rs

16 lines
278 B
Rust
Raw Normal View History

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).
2012-03-27 22:08:48 -07:00
// error-pattern:assigning to immutable field
class cat {
priv {
let mutable meows : uint;
}
let how_hungry : int;
Require "self" as base expression for intra-class method or field references All field or method references within a class must begin with "self." now. A bare reference to a field or method in the same class will no longer typecheck.
2012-03-29 12:21:13 -07:00
new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
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).
2012-03-27 22:08:48 -07:00
}
fn main() {
let nyan : cat = cat(52u, 99);
nyan.how_hungry = 0;
}
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.24.6 Page: 226ms Template: 3ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API