Skip to content

Commit

Permalink
Wantify middle args for notandthen/andthen/orelse
Browse files Browse the repository at this point in the history
Since these affect the final outcome of the chain, they're
always wanted.

This should probably be fixed in the place that marks first
arg as wanted, but I'm failing to find where that occurs.

Fixes RT#131499: https://rt.perl.org/Ticket/Display.html?id=131499
  • Loading branch information
zoffixznet committed Jan 10, 2018
1 parent 86d91f2 commit d30e5b1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Perl6/Actions.nqp
Expand Up @@ -6585,6 +6585,15 @@ class Perl6::Actions is HLL::Actions does STDActions {
$past := thunkity_thunk($/, $thunky,
QAST::Op.new( :op('call'), :name("&infix" ~ $*W.canonicalize_pair('', $sym))),
$/.list);

unless $sym eq 'xx' {
# andthen/notandthen/orelse ops can be chained and since all but last
# args affect the outcome of the chain, all but last args are wanted
my $up-to := @($past) - 2;
my $i := 1; # first arg gets marked as wanted elsewhere; skip it
wanted($past[$i++], "$sym/args") while $i <= $up-to;
}

make $past;
return 1;
}
Expand Down
24 changes: 23 additions & 1 deletion t/05-messages/10-warnings.t
Expand Up @@ -2,7 +2,7 @@ use lib <t/packages/>;
use Test;
use Test::Helpers;

plan 2;
plan 3;

subtest 'Supply.interval with negative value warns' => {
plan 2;
Expand Down Expand Up @@ -39,4 +39,26 @@ else {
, :err(''), 'no warnings with UNDO phaser';
}
}

if $*DISTRO.is-win {
skip 'is-run code is too complex to run on Windows (RT#132258)';
}
else {
subtest 'no useless-use warning in andthen/notandthen/orelse/ chains' => {
plan 2;
is-run
1 notandthen 2 notandthen 3 notandthen 4;
5 andthen 6 andthen 7 andthen 8;
9 orelse 10 orelse 11 orelse 12;
, :err{ 3 == .comb: 'Useless use' },
'we get warnings when last value is useless';

is-run
2 notandthen 2 notandthen 2 notandthen 2.uc;
2 andthen 2 andthen 2 andthen 2.uc;
2 orelse 2 orelse 2 orelse 2.uc;
, 'no warnings when last value is useful';
}
}

# vim: ft=perl6 expandtab sw=4

0 comments on commit d30e5b1

Please sign in to comment.