Skip to content

Commit 6d5f8c5

Browse files
committed
---
yaml --- r: 12101 b: refs/heads/master c: aae14e3 h: refs/heads/master i: 12099: 2044c6e v: v3
1 parent 1e90e5f commit 6d5f8c5

File tree

5 files changed

+75
-7
lines changed

5 files changed

+75
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: bebdfe8ce8dd737a34625ed1ee6336dbdecf058c
2+
refs/heads/master: aae14e352af95ad70d862e0e952d3817fc6c9c27
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rustc/middle/trans/base.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,7 +2241,16 @@ fn trans_var(cx: block, def: ast::def, id: ast::node_id, path: @ast::path)
22412241
}
22422242
_ { cx.sess().bug("unbound self param in class"); }
22432243
}
2244-
}
2244+
}
2245+
ast::def_class_method(parent, did) {
2246+
alt cx.fcx.llself {
2247+
some(slf) {
2248+
ret {env: self_env(slf.v, slf.t, none)
2249+
with lval_static_fn(cx, did, id)};
2250+
}
2251+
none { cx.sess().bug("unbound self param in class"); }
2252+
}
2253+
}
22452254
_ {
22462255
let loc = trans_local_var(cx, def);
22472256
ret lval_no_env(cx, loc.val, loc.kind);
@@ -2266,7 +2275,11 @@ fn trans_rec_field_inner(bcx: block, val: ValueRef, ty: ty::t,
22662275
_ { bcx.tcx().sess.span_bug(sp, "trans_rec_field:\
22672276
base expr has non-record type"); }
22682277
};
2269-
let ix = option::get(ty::field_idx(field, fields));
2278+
let ix = alt ty::field_idx(field, fields) {
2279+
none { bcx.tcx().sess.span_bug(sp, #fmt("trans_rec_field:\
2280+
base expr doesn't appear to have a field named %s", field));}
2281+
some(i) { i }
2282+
};
22702283
let val = GEPi(bcx, val, [0, ix as int]);
22712284
ret {bcx: bcx, val: val, kind: owned};
22722285
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
mod kitties {
2+
3+
class cat {
4+
priv {
5+
let mutable meows : uint;
6+
fn meow() {
7+
#error("Meow");
8+
meows += 1u;
9+
if meows % 5u == 0u {
10+
how_hungry += 1;
11+
}
12+
}
13+
}
14+
15+
let how_hungry : int;
16+
17+
new(in_x : uint, in_y : int) { meows = in_x; how_hungry = in_y; }
18+
19+
fn speak() { meow(); }
20+
21+
fn eat() -> bool {
22+
if how_hungry > 0 {
23+
#error("OM NOM NOM");
24+
how_hungry -= 2;
25+
ret true;
26+
}
27+
else {
28+
#error("Not hungry!");
29+
ret false;
30+
}
31+
}
32+
}
33+
34+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// xfail-fast
2+
// aux-build:cci_class_4.rs
3+
use cci_class_4;
4+
import cci_class_4::kitties::*;
5+
6+
fn main() {
7+
let nyan = cat(0u, 2);
8+
nyan.eat();
9+
assert(!nyan.eat());
10+
uint::range(1u, 10u, {|_i| nyan.speak(); });
11+
assert(nyan.eat());
12+
}

trunk/src/test/run-pass/classes.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
// xfail-test
21
class cat {
32
priv {
43
let mutable meows : uint;
54
fn meow() {
65
#error("Meow");
7-
meows += 1;
8-
if meows % 5 == 0 {
6+
meows += 1u;
7+
if meows % 5u == 0u {
98
how_hungry += 1;
109
}
1110
}
@@ -17,13 +16,23 @@ class cat {
1716

1817
fn speak() { meow(); }
1918

20-
fn eat() {
19+
fn eat() -> bool {
2120
if how_hungry > 0 {
2221
#error("OM NOM NOM");
2322
how_hungry -= 2;
23+
ret true;
2424
}
2525
else {
2626
#error("Not hungry!");
27+
ret false;
2728
}
2829
}
30+
}
31+
32+
fn main() {
33+
let nyan = cat(0u, 2);
34+
nyan.eat();
35+
assert(!nyan.eat());
36+
uint::range(1u, 10u, {|_i| nyan.speak(); });
37+
assert(nyan.eat());
2938
}

0 commit comments

Comments
 (0)