Skip to content

Commit 8016512

Browse files
committed
Point out difference in where clause...
...between block and non-block versions. RT#131239: https://rt.perl.org/Ticket/Display.html?id=131239
1 parent c991862 commit 8016512

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

doc/Type/Signature.pod6

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,21 @@ The first of those can be shortened to
139139
i.e., you can use a literal directly as a type and value constraint
140140
on an anonymous parameter.
141141
142+
B<Tip:> pay attention to not accidentally leave off a block when you,
143+
say, have several conditions:
144+
145+
-> $y where .so && .name {}( sub foo {} ) # WRONG!!
146+
-> $y where { .so && .name } {}( sub foo {} ) # OK!
147+
-> $y where .so & .name.so {}( sub foo {} ) # Also good
148+
149+
The first version is wrong and will issue a warning about sub object coerced
150+
to string. The reason is the expression is equivalent to
151+
C<($y ~~ ($y.so && $y.name))>; that is "call C<.so>, and if that is C<True>,
152+
call C<.name>; if that is also C<True> use its value for smartmatching…". It's
153+
the B<result> of C<(.so && .name)> is will be smartmatched against, but we
154+
want to check that both C<.so> and C<.name> are truthy values. That is why
155+
an explict Block or a L<Junction> is the right version.
156+
142157
All previous arguments that are not part of a sub-signature in a C<Signature>
143158
are accessible in a C<where>-clause that follows an argument. Therefore,
144159
the C<where>-clause of the last argument has access to all arguments of a

0 commit comments

Comments
 (0)