Skip to content

Commit 2f70d11

Browse files
committed
Test attr access in attr's where throws good error
RT#130748: https://rt.perl.org/Ticket/Display.html?id=130748 Rakudo fix: rakudo/rakudo@1c894e418d
1 parent 410a398 commit 2f70d11

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

S12-attributes/class.t

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Class Attributes
1414
#L<S12/Class attributes/"Class attributes are declared">
1515
#L<S12/Class methods/Such a metaclass method is always delegated>
1616

17-
plan 23;
17+
plan 24;
1818

1919
class Foo {
2020
our $.bar = 23;
@@ -141,4 +141,29 @@ is_run(
141141
'useless my $.a accessor method generation error contains useful enough hints'
142142
);
143143

144+
# RT #130748
145+
subtest 'attribute access from where clauses' => {
146+
plan 7;
147+
throws-like my class RT130748a { has $.a; has $.b where $!a },
148+
X::Syntax::NoSelf, 'where, thunk, attr only';
149+
throws-like my class RT130748b { has $.a; has $.b where * > $!a },
150+
X::Syntax::NoSelf, 'where, whatevercode';
151+
throws-like my class RT130748c { has $.a; has $.b where {$!a},
152+
X::Syntax::NoSelf, 'where, block';
153+
154+
my class RT130748d {
155+
has $.a = 42;
156+
has $.b where *.so = $!a+1;
157+
method z-thunk ($x where $!a ) { pass 'where in method param, thunk' }
158+
method z-block ($x where {$!a}) { pass 'where in method param, block' }
159+
method z-whatever ($x where *+$!a) {
160+
pass 'where in method param, whatevercode'
161+
}
162+
}
163+
is-deeply RT130748d.new.b, 43, 'can still use attr in default values';
164+
RT130748d.new.z-thunk: 42;
165+
RT130748d.new.z-block: 42;
166+
RT130748d.new.z-whatever: 42;
167+
}
168+
144169
# vim: ft=perl6

0 commit comments

Comments
 (0)