diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-12-18 19:30:40 +0100 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-12-18 19:41:44 +0100 |
| commit | f4acaf6934bf836e6d3feb14738378366f47bef0 (patch) | |
| tree | 736fc558d90143d84d62e73cd1159edccb2e4ce7 /src/test | |
| parent | b36ade1367a2dbca69386b58d225ceafa6a90d57 (diff) | |
| download | rust-f4acaf6934bf836e6d3feb14738378366f47bef0.tar.gz rust-f4acaf6934bf836e6d3feb14738378366f47bef0.zip | |
Only look for a matching method when normal field access fails
We should probalby warn when defining a method foo on {foo: int} etc.
This should reduce the amount of useless typevars that are allocated.
Issue #1227
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/direct-obj-fn-call.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/self-missing-method.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/vec-field.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/static-impl.rs | 25 |
4 files changed, 27 insertions, 4 deletions
diff --git a/src/test/compile-fail/direct-obj-fn-call.rs b/src/test/compile-fail/direct-obj-fn-call.rs index 01ec855bf7c..cb6557dea8c 100644 --- a/src/test/compile-fail/direct-obj-fn-call.rs +++ b/src/test/compile-fail/direct-obj-fn-call.rs @@ -1,4 +1,4 @@ -// error-pattern: attempted field access +// error-pattern: attempted access of field hello obj x() { fn hello() { log "hello"; } diff --git a/src/test/compile-fail/self-missing-method.rs b/src/test/compile-fail/self-missing-method.rs index b9c7086f6e7..21069a4832e 100644 --- a/src/test/compile-fail/self-missing-method.rs +++ b/src/test/compile-fail/self-missing-method.rs @@ -1,4 +1,4 @@ -// error-pattern:attempted field access on type fn +// error-pattern:attempted access of field m on type fn fn main() { obj foo() { diff --git a/src/test/compile-fail/vec-field.rs b/src/test/compile-fail/vec-field.rs index 1ec888670c4..9e2c54003fe 100644 --- a/src/test/compile-fail/vec-field.rs +++ b/src/test/compile-fail/vec-field.rs @@ -1,4 +1,4 @@ -// error-pattern:attempted field access on type [int] +// error-pattern:attempted access of field some_field_name on type [int] // issue #367 fn f() { diff --git a/src/test/run-pass/static-impl.rs b/src/test/run-pass/static-impl.rs index ab4fbc5915f..9d245a22bb7 100644 --- a/src/test/run-pass/static-impl.rs +++ b/src/test/run-pass/static-impl.rs @@ -9,10 +9,33 @@ mod b { impl baz for str { fn plus() -> int { 200 } } } +impl util for uint { + fn str() -> str { uint::str(self) } + fn times(f: block(uint)) { + let c = 0u; + while c < self { f(c); c += 1u; } + } +} + +impl util<T> for [T] { + fn len() -> uint { vec::len(self) } + fn iter(f: block(T)) { for x in self { f(x); } } + fn map<U>(f: block(T) -> U) -> [U] { + let r = []; + for elt in self { r += [f(elt)]; } + r + } +} + fn main() { impl foo for int { fn plus() -> int { self + 10 } } assert 10.plus() == 20; assert 10u.plus() == 30; assert "hi".plus() == 200; -} + assert [1].len().str() == "1"; + assert [3, 4].map({|a| a + 4})[0] == 7; + let x = 0u; + 10u.times {|_n| x += 2u;} + assert x == 20u; +} |
