Skip to content

Commit 11610f9

Browse files
committed
In typeck, don't call ty::store_iface_methods on private methods
This was resulting in a different error message depending on whether the private method you were trying to call was in the same crate or a different one.
1 parent 2111166 commit 11610f9

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

src/rustc/middle/typeck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,8 @@ mod collect {
934934
}
935935
ast_map::node_item(@{node: ast::item_class(_,its,_), _}, _) {
936936
let (_,ms) = split_class_items(its);
937-
// Handling all methods here
938-
let ps = ast_util::ignore_privacy(ms);
937+
// Only public methods need to be stored
938+
let ps = ast_util::public_methods(ms);
939939
store_methods::<@ast::method>(tcx, id, ps, {|m|
940940
ty_of_method(tcx, m_collect, m)});
941941
}

src/test/auxiliary/cci_class_5.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
mod kitties {
2+
3+
class cat {
4+
priv {
5+
let mutable meows : uint;
6+
fn nap() { uint::range(1u, 10000u) {|_i|}}
7+
}
8+
9+
let how_hungry : int;
10+
11+
new(in_x : uint, in_y : int) { meows = in_x; how_hungry = in_y; }
12+
}
13+
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// error-pattern:no public field or method with that name
2+
// xfail-fast
3+
// aux-build:cci_class.rs
4+
use cci_class;
5+
import cci_class::kitties::*;
6+
7+
fn main() {
8+
let nyan : cat = cat(52u, 99);
9+
assert (nyan.meows == 52u);
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// error-pattern:attempted access of field nap on type
2+
// xfail-fast
3+
// aux-build:cci_class_5.rs
4+
use cci_class_5;
5+
import cci_class_5::kitties::*;
6+
7+
fn main() {
8+
let nyan : cat = cat(52u, 99);
9+
nyan.nap();
10+
}

src/test/compile-fail/private-method.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// error-pattern:Class doesn't have a public method named nap
1+
// error-pattern:attempted access of field nap on type
22
class cat {
33
priv {
44
let mutable meows : uint;

0 commit comments

Comments
 (0)