-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In resolve, visit the path in an iface ref
Necessary to resolve any type arguments in a ref to a parameterized iface. This meant that, for example: class A implements B<int> { ... didn't work before, because the "int" in B's argument wasn't getting visited, and thus wasn't getting resolved. Now it works. Partially addresses Issue #2288, but I also want to check that class ty params can appear as the type arguments to ifaces (for example, class A<T> implements B<T> {... should work.)
- Loading branch information
1 parent
1226669
commit 4f105e4
Showing
6 changed files
with
109 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// xfail-fast | ||
use std; | ||
import std::map::*; | ||
|
||
class cat implements map<int, bool> { | ||
priv { | ||
// Yes, you can have negative meows | ||
let mut meows : int; | ||
fn meow() { | ||
self.meows += 1; | ||
#error("Meow %d", self.meows); | ||
if self.meows % 5 == 0 { | ||
self.how_hungry += 1; | ||
} | ||
} | ||
} | ||
|
||
let mut how_hungry : int; | ||
let name : str; | ||
|
||
new(in_x : int, in_y : int, in_name: str) | ||
{ self.meows = in_x; self.how_hungry = in_y; self.name = in_name; } | ||
|
||
fn speak() { self.meow(); } | ||
|
||
fn eat() -> bool { | ||
if self.how_hungry > 0 { | ||
#error("OM NOM NOM"); | ||
self.how_hungry -= 2; | ||
ret true; | ||
} | ||
else { | ||
#error("Not hungry!"); | ||
ret false; | ||
} | ||
} | ||
|
||
fn size() -> uint { self.meows as uint } | ||
fn insert(&&k: int, &&v: bool) -> bool { | ||
if v { self.meows += k; } else { self.meows -= k; }; | ||
true | ||
} | ||
fn contains_key(&&k: int) -> bool { k <= self.meows } | ||
fn get(&&k:int) -> bool { k <= self.meows } | ||
fn find(&&k:int) -> option<bool> { some(self.get(k)) } | ||
fn remove(&&k:int) -> option<bool> { self.meows -= k; some(true) } | ||
fn each(f: fn(&&int, &&bool) -> bool) { | ||
let mut n = int::abs(self.meows); | ||
while n > 0 { | ||
if !f(n, true) { break; } | ||
n -= 1; | ||
} | ||
} | ||
fn each_key(&&f: fn(&&int) -> bool) { | ||
for self.each {|k, _v| if !f(k) { break; } cont;}; | ||
} | ||
fn each_value(&&f: fn(&&bool) -> bool) { | ||
for self.each {|_k, v| if !f(v) { break; } cont;}; | ||
} | ||
} | ||
|
||
fn main() { | ||
let nyan : cat = cat(0, 2, "nyan"); | ||
uint::range(1u, 5u) {|_i| nyan.speak(); } | ||
// cat returns true if uint input is greater than | ||
// the number of meows so far | ||
assert(nyan.get(1)); | ||
assert(!nyan.get(10)); | ||
} |