Skip Menu |
Report information
Id: 129025
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: ddgreen [at] gmail.com
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [RFC] Warn the user if there is any code in a given block after the default or a when { * }
Download (untitled) / with headers
text/plain 189b
This bit me at first when I was changing some conditions around. E.g., given 'a' { when Int { say 'Life...' } default { say 'this does get run' } say 'this does not get run'; }
On Sat Aug 20 20:13:32 2016, ddgreen@gmail.com wrote: Show quoted text
> This bit me at first when I was changing some conditions around. > E.g., > given 'a' { > when Int { say 'Life...' } > default { say 'this does get run' } > say 'this does not get run'; > }
http://irclog.perlgeek.de/perl6/2016-08-21#i_13061970 03:10 TimToady ShimmerFairy: seems like warning after a default or a when * would make sense 03:11 ShimmerFairy yeah, that's fine and it seems like it'd be far easier than doing it after 'when' blocks. 03:11 TimToady and we could presumably know the outcome at compile time if the given was a constant, but maybe they're just writing it that way to select code for one architecture or another 03:12 ShimmerFairy TimToady: I don't imagine code after a default {} would be very useful unless you played around with labels and gotos, so there should certainly be a warning. 03:12 TimToady and otherwise the situation is unlikely to arise in practice 03:12 mainly you have the situation where someone puts the default first because they're thining C semantics 03:12 thinking, even
On Sat Aug 20 20:17:46 2016, ddgreen@gmail.com wrote: Show quoted text
> On Sat Aug 20 20:13:32 2016, ddgreen@gmail.com wrote:
> > This bit me at first when I was changing some conditions around. > > E.g., > > given 'a' { > > when Int { say 'Life...' } > > default { say 'this does get run' } > > say 'this does not get run'; > > }
> > http://irclog.perlgeek.de/perl6/2016-08-21#i_13061970 > > 03:10 TimToady ShimmerFairy: seems like warning after a > default or a when * would make sense > 03:11 ShimmerFairy yeah, that's fine and it seems like it'd be > far easier than doing it after 'when' blocks. > 03:11 TimToady and we could presumably know the outcome at > compile time if the given was a constant, but maybe they're just > writing it that way to select code for one architecture or another > 03:12 ShimmerFairy TimToady: I don't imagine code after a default > {} would be very useful unless you played around with labels and > gotos, so there should certainly be a warning. > 03:12 TimToady and otherwise the situation is unlikely to > arise in practice > 03:12 mainly you have the situation where someone puts the > default first because they're thining C semantics > 03:12 thinking, even
timotimo has some examples that show this is a hard problem. http://irclog.perlgeek.de/perl6/2016-08-21#i_13062573 10:45 timotimo m: sub the_thing { succeed }; given 42 { default { say "vroom"; the_thing }; say "doesn't get run ... ?" } 10:45 camelia rakudo-moar 668dc5: OUTPUT«vroom␤» 10:45 timotimo m: sub the_thing { proceed }; given 42 { default { say "vroom"; the_thing }; say "doesn't get run ... ?" } 10:45 camelia rakudo-moar 668dc5: OUTPUT«vroom␤doesn't get run ... ?␤» 10:49 MasterDuke timotimo: interesting, that does seem to make it a bit harder to detect code that won't get run 10:50 timotimo definitely 10:50 i've got something that's even worse :) 10:51 m: my $*OUT = class { method print($_) { note $_; proceed } }; given 42 { default { say "vroom" }; say "doesn't get run ... ?" } 10:51 camelia rakudo-moar 668dc5: OUTPUT«vroom␤␤doesn't get run ... ?␤␤proceed without when clause␤ in method print at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤» 10:51 timotimo m: my $*OUT = class { method print($_) { note $_; proceed CATCH { default { } } } }; given 42 { default { say "vroom" }; say "doesn't get run ... ?" } 10:51 camelia rakudo-moar 668dc5: OUTPUT«5===SORRY!5=== Error while compiling <tmp>␤Undeclared name:␤ CATCH used at line 1. Did you mean 'Match'?␤␤» 10:51 timotimo m: my $*OUT = class { method print($_) { note $_; proceed; CATCH { default { } } } }; given 42 { default { say "vroom" }; say "doesn't get run ... ?" } 10:51 camelia rakudo-moar 668dc5: OUTPUT«vroom␤␤doesn't get run ... ?␤␤» 10:52 timotimo you don't even have to put it into a dynamic variable in scope, you can put it into PROCESS:: 10:52 at least i think so? 10:55 so, yeah. never going to be able to analyze that statically :) 10:55 until we have link-time analysis of things


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org