Skip to content

Commit

Permalink
Merge pull request #20796 from lydia-duncan/addConstForwardTest
Browse files Browse the repository at this point in the history
Add a tests tracking the behavior with forwarding
[new tests, not reviewed]

Adds two tests:
- forwarding const methods
- forwarding iterators

I don't think either of these cases were explicitly tracked today, but they
work if I get the forwarding statement right (which I didn't right away).

Passed a fresh checkout
  • Loading branch information
lydia-duncan authored Oct 10, 2022
2 parents 41a404b + 5960270 commit 99825b9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/classes/forwarding/constMethod.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
record Foo {
var b: shared Bar?;
forwarding b!;

proc init() {
b = new shared Bar();
}
}

class Bar {
proc const whatever() {
return 16;
}
}

proc main() {
var f = new Foo();
writeln(f.whatever());
}
1 change: 1 addition & 0 deletions test/classes/forwarding/constMethod.good
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
30 changes: 30 additions & 0 deletions test/classes/forwarding/forwardIterator.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
record Foo {
var b: shared Bar?;
forwarding b!;

proc init(num: int) {
b = new shared Bar(num);
}
}

class Bar {
var r: range;

proc init(num: int) {
r = 0..#num;
}

iter all() {
for i in r {
yield i;
}
}
}

proc main() {
var f = new Foo(10);

for i in f.all() {
writeln(i);
}
}
10 changes: 10 additions & 0 deletions test/classes/forwarding/forwardIterator.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
0
1
2
3
4
5
6
7
8
9

0 comments on commit 99825b9

Please sign in to comment.