develooper Front page | perl.perl5.porters | Postings from August 2012

[perl #77510] when() as a statement modifier outside a topicalizer both works and fails

Thread Next
From:
Father Chrysostomos via RT
Date:
August 19, 2012 12:07
Subject:
[perl #77510] when() as a statement modifier outside a topicalizer both works and fails
Message ID:
rt-3.6.HEAD-11172-1345403236-984.77510-15-0@perl.org
On Sun Aug 29 22:29:58 2010, comdog wrote:
> This is a bug report for perl from brian.d.foy@gmail.com,
> generated with the help of perlbug 1.39 running under perl 5.12.1.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> Perl 5.12 allows when() as a statement modifier. I think this
> is only intended inside a topicalizer, but it parses just
> fine outside a topicalizer.
> 
> This script compiles just fine:
> 
> 	use 5.012;
> 
> 	my %microchips = (
> 		  'Mimi'   => 123,
> 		  'Buster' => undef,
> 		  'Roscoe' => 345,
> 		);
> 
> 	say "Known cats are @{[keys %microchips]}\n";
> 	{
> 	print "Enter a cat name> ";
> 	chomp( $_ = <STDIN> );
> 	say "Found cat with id $microchips{$_}" when %microchips;
> 	redo;
> 	}
> 
> Now, when I run this and respond to a prompt with a cat's name
> that is in the hash, the say() outputs its message and Perl
> dies:
> 
> 	Buster
> 	Found cat with id
> 	Can't use when() outside a topicalizer at test line 11, <STDIN> line
> 
> That's fine, but I don't get the same error when I respond with
> a cat's name that is not in the hash:
> 
> 	Enter a cat name> Ella
> 	Enter a cat name> Buster
> 	Found cat with id
> 	Can't use when() outside a topicalizer at test line 12, <STDIN> line
>    2.
> 
> That is, the when() always works. If its condition is true, it also
>    dies. If
> its condition is false, it does not die.
> 
> I verified this with all released versions of 5.12 and 5.13.
> 
> I figure this should be a compile-time error, or, if we're really
>    lazy, just
> never die.

Clarifying the error message might help.  If we make it clear that
‘when’ is having trouble *exiting* a topicalizer, I think that would be
good enough.  But I can’t find a good way of wording it.

We currently have:

Can't "when" outside a topicalizer

But it should be more like:

"when" can't break outside a topicalizer

But ‘break outside’ could be misconstrued as ‘break out of’.  Maybe:

"when" can't break without a topicalizer

(The archaistic could make the same argument about that one.)

"when" can't find a topicalizer to exit
"when" can't break except from inside a topicalizer

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=77510

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About