The other day when I was working on Perl's regexp (?{...}) construct and constraining matches. I came across a strange error message. Before I start in, let me state that I'm fully aware that (?{...}) is considered a "highly experimental" feature, and that I should expect quirks. But that said, here's the background:

The following code will produce a runtime warning:

print rand + 5;

The warning will be:

Warning: Use of "rand" without parentheses is ambiguous at mytest.pl line 4 (#1)

This is understandable (though it's one case where whitespace does matter, as "print rand +5;" doesn't trigger a warning), and the information returned from 'use diagnostics' pretty much tells the story:

Warning: Use of "rand" without parentheses is ambiguous at mytest.pl l +ine 4 (#1) (S ambiguous) You wrote a unary operator followed by something tha +t looks like a binary operator that could also have been interpreted + as a term or unary operator. For instance, if you know that the rand function has a default argument of 1.0, and you write rand + 5; you may THINK you wrote the same thing as rand() + 5; but in actual fact, you got rand(+5); So put in parentheses to say what you really mean.

Now look at the following snippet, which commits the same faux pax within a (?{ code }) block of a regular expression:

use strict; use warnings; use diagnostics; my $string = "1230000000"; print $string =~ m/123(?{(pos <= length($_)*.5) ? '(?=)':'(?!)'})(??{$ +^R})/ ? "Matched.\n" : "Didn't match.\n"; __OUTPUT__ Warning: Use of "pos" without parentheses is ambiguous at (re_eval 2) +line 1 (#1 ) (S ambiguous) You wrote a unary operator followed by something tha +t looks like a binary operator that could also have been interpreted + as a term or unary operator. For instance, if you know that the rand function has a default argument of 1.0, and you write rand + 5; you may THINK you wrote the same thing as rand() + 5; but in actual fact, you got rand(+5); So put in parentheses to say what you really mean. panic: top_env

Again, the same warning, and the same diagnostic message: no problem. But what's with the "panic:  top_env" message? And why doesn't it print out a diagnostic too?

Looking in perldiag I found the following:

(P) An internal error you should never see (trappable).
....
panic: top_env
(P) The compiler attempted to do a goto, or something weird like that.

First, what is this? Second, since I "should never see" this, does the fact that I am seeing it indicate that I should submit a perlbug report?

With similar snippets I've also managed to trigger the following similar error:

panic: restartop (P) Some internal routine requested a goto (or something like it), and + didn't supply the destination.

Though I can't remember how to reproduce the latter, they seem related. I cannot help but think that if I'm seeing these sorts of messages, there is a loose end somewhere in Perl that needs to be tied up. Any voices of agreement or disagreement?


Dave


In reply to "panic: top_env": Is this error resulting from a Perl bug? by davido

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.