Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 21234
Status: resolved
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: stephen [...] jadevine.org.uk
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.19
Fixed in: (no value)



Subject: conflicting tests in some cases
If the last line of code in a subroutine is a die() or exit(), I get the severity 4 warning: Subroutine does not end with "return" at line 11, column 1. See page 197 of PBP. (Severity: 4) If I try to fix this by adding a return as the last line of code I then get the severity 4 warning: Unreachable code at line 8, column 5. Consider removing it. (Severity: 4) So, which should I do? It would be nice if Perl::Critic could come up with a solution to this situation. I've attached a simple perl script with two subs which demonstrates the problem. Thanks, Stephen Quinney
Subject: critic-test.pl
#!/usr/bin/perl use strict; use warnings; sub test1 { die "foo\n"; return; } sub test2 { die "foo\n"; }
Subject: Re: [rt.cpan.org #21234] conflicting tests in some cases
Date: Wed, 30 Aug 2006 08:41:55 -0500
To: bug-Perl-Critic [...] rt.cpan.org
From: Chris Dolan <chris [...] chrisdolan.net>
On Aug 30, 2006, at 7:05 AM, Stephen Quinney via RT wrote: Show quoted text
> If the last line of code in a subroutine is a die() or exit(), I > get the > severity 4 warning: > > Subroutine does not end with "return" at line 11, column 1. See page > 197 of PBP. (Severity: 4) > > If I try to fix this by adding a return as the last line of code I > then > get the severity 4 warning: > > Unreachable code at line 8, column 5. Consider removing it. > (Severity: 4) > > So, which should I do? It would be nice if Perl::Critic could come up > with a solution to this situation. > > I've attached a simple perl script with two subs which demonstrates > the > problem. > > Thanks, > > Stephen Quinney
Stephen, Thanks for the report. I've seen this same issue in my own code, but haven't had a chance to address it. I've done like so as a workaround: sub foo { die; return; ##no critic(PrehibitUnreachableCode) } Probably the best solution is for RequireEndsWithReturn to allow die (), croak() and confess(). But I need to think about it a little more. Chris
This was resolved in Perl-Critic-0.21