Skip to content

Commit d1b71f3

Browse files
committed
Expand test 25 to check that methods have access to surrounding nonstatic lexicals.
1 parent f888397 commit d1b71f3

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

t/nqp/25-class.t

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
# class
44

5-
plan(2);
5+
plan(5);
66

77
class XYZ {
88
method foo($x) {
9-
say($x);
9+
ok($x eq 'ok 1');
1010
}
1111
}
1212

@@ -19,11 +19,29 @@ $xyz.foo('ok 1');
1919

2020
class QRS {
2121
method foo($x) {
22-
say($x);
22+
ok($x eq 'ok 2');
2323
}
2424
}
2525

2626
my $qrs := QRS.new();
2727

2828
$qrs.foo('ok 2');
2929

30+
class ABC {
31+
my $foo := 15;
32+
my sub helper($x) {
33+
$x*2;
34+
}
35+
method foo($x) {
36+
helper($x);
37+
}
38+
method bar($x) {
39+
$foo := $foo + $x;
40+
$foo;
41+
}
42+
}
43+
44+
my $abc := ABC.new();
45+
ok($abc.foo(100) == 200,"using a lexical sub inside a method");
46+
ok($abc.bar(10) == 25,"using a outer lexical inside a method");
47+
ok($abc.bar(1) == 26,"the value of the lexical persisting");

0 commit comments

Comments
 (0)