Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn the user if there is any code in a given block after the default or a when { * } #5609

Open
p6rt opened this issue Aug 21, 2016 · 3 comments
Labels
RFC Request For Comments

Comments

@p6rt
Copy link

p6rt commented Aug 21, 2016

Migrated from rt.perl.org#129025 (status was 'new')

Searchable as RT129025$

@p6rt
Copy link
Author

p6rt commented Aug 21, 2016

From @MasterDuke17

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';
}

@p6rt
Copy link
Author

p6rt commented Aug 21, 2016

From @MasterDuke17

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

@p6rt
Copy link
Author

p6rt commented Aug 21, 2016

From @MasterDuke17

On Sat Aug 20 20​:17​:46 2016, ddgreen@​gmail.com wrote​:

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

@p6rt p6rt added the RFC Request For Comments label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request For Comments
Projects
None yet
Development

No branches or pull requests

1 participant