Skip to content

Commit

Permalink
Add failing test.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpressey committed Feb 17, 2022
1 parent 5532b16 commit 4520d99
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/Castile.md
Original file line number Diff line number Diff line change
Expand Up @@ -1390,3 +1390,45 @@ One can use this facility to implement abstract data types.
= um
= second
= ya

This program should work even with a redundant upcast in it.

| struct assoc {
| key: string;
| value: string;
| next: assoc|void;
| } for (singleton, update, lookup, remove)
|
| fun singleton(k: string, v: string) {
| make assoc(key:k, value:v, next:null as assoc|void)
| }
|
| fun update(k: string, v: string, a: assoc) {
| make assoc(key:k, value:v, next:a as assoc|void)
| }
|
| lookup : assoc, string -> string|void
| fun lookup(a: assoc, k: string) {
| if a.key == k {
| return a.value as string|void
| }
| n = a.next
| typecase n is void {
| return null as string|void
| }
| typecase n is assoc {
| return lookup(n, k) as string|void
| }
| }
|
| fun main() {
| a = update("1", "first", update("2", "second", singleton("3", "third")));
| r = lookup(a, "2");
| print("um");
| typecase r is void { print("NOT FOUND"); }
| typecase r is string { print(r); }
| print("ya");
| }
= um
= second
= ya

0 comments on commit 4520d99

Please sign in to comment.