http://www.perlmonks.org?node_id=1036206

shmem has asked for the wisdom of the Perl Monks concerning the following question:

Update: Scratch that, reap the post, call me a fool. I should have invoked perl with the -l switch. The behavior is consistent. I dinn' catch the string "bug!" just in front of the shell prompt.

Update: changed title

Dear fellow monks,

playing with prototypes for a future perl talk at $work, I stumbled over the following (perl v5.14.3):

# file proto.pl sub fn($); fn("no bug."); sub fn (\@) { print while $_ = shift; } __END__ Prototype mismatch: sub main::fn ($) vs (\@) at proto.pl line 6.

That's fine and expected.
However, if the parameter list @_ isn't altered via shift, the fatal error is turned into a warning:

# file proto.pl sub fn($); fn("bug!"); sub fn (\@) { print $_,$/ for @_; } __END__ Prototype mismatch: sub main::fn ($) vs (\@) at proto.pl line 6. bug!

Would you consider that a bug, and if so, is it worth reporting?

Replies are listed 'Best First'.
Re: yet another prototype bug?
by LanX (Saint) on May 31, 2013 at 10:21 UTC
    hmm ...can't reproduce!

    For me both cases are consistent and throw warnings instead of dieing

    perl -version This is perl, v5.10.0 built for i486-linux-gnu-thread-multi

    code:
    BEGIN { $SIG{__WARN__}=sub { print "WARNING: $_[0] \n" }; } $|=1; sub fn1($); fn1("output1"); sub fn1 (\@) { print while $_ = shift; } sub fn2($); fn2("output2"); sub fn2 (\@) { print $_,$/ for @_; }

    output:

    $ perl /tmp/proto.pl WARNING: Prototype mismatch: sub main::fn1 ($) vs (\@) at /tmp/proto.p +l line 11. WARNING: Prototype mismatch: sub main::fn2 ($) vs (\@) at /tmp/proto.p +l line 18. output1output2

    If you want it do die try to catch the /^Prototype mismatch:/ in $SIG{__WARN__}

    Cheers Rolf

    ( addicted to the Perl Programming Language)

    UPDATE

    ¹) or check if categories in warnings help defining "Fatals" on "Prototype mismatch".
Re: yet another prototype bug?
by choroba (Cardinal) on May 31, 2013 at 10:35 UTC
    I am getting the output from both the examples and the warnings only on 5.10.1, 5.12.2, 5.14.1 and 5.16.0. Ubuntu 10.04.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: yet another prototype bug?
by Anonymous Monk on May 31, 2013 at 10:35 UTC
    FWIW, neither version croaks, both warn and print the string, on win32 perls v5.8.9, v5.14.1, v5.16.1
Re: yet another prototype bug?
by BrowserUk (Patriarch) on May 31, 2013 at 10:23 UTC

    Fatal because you cannot shift a scalar; non-fatal because you can print one?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Fatal because you cannot shift a scalar;

      No, I'm not shifting a scalar. Inside a sub shift without argument operates on @_.

        Good point.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: yet another prototype bug?
by Anonymous Monk on May 31, 2013 at 10:26 UTC

    Would you consider that a bug,

    AFAIK, its undefined behaviour, thus not a bug

    and if so, is it worth reporting?

    Yes, at a minimum it might improve the docs (hey, don't do that)