develooper Front page | perl.perl5.porters | Postings from December 2011

[perl #24684] Too late warning not given for CHECK block in INIT block

Thread Previous | Thread Next
Matthew Horsfall via RT
December 17, 2011 20:36
[perl #24684] Too late warning not given for CHECK block in INIT block
Message ID:
Thanks for the report.

This is because when nothing is actually happening in the main scope of
the program it's treated as an OP_STUB which causes Perl_newPROG() to
skip out before setting PL_main_start; which is what the warning requires:

(Inside of Perl_newprog()):

         if (o->op_type == OP_STUB) {
            PL_comppad_name = 0;
            PL_compcv = 0;
            S_op_destroy(aTHX_ o);

            return; < -- Returns here
        PL_main_root = op_scope(sawparens(scalarvoid(o)));
        PL_curcop = &PL_compiling;
        PL_main_start = LINKLIST(PL_main_root); < -- This is needed

(The warning check:)

                if (PL_main_start)
                    Perl_ck_warner(aTHX_ packWARN(WARN_VOID),
                                   "Too late to run CHECK block");

This warns correctly for example:

 perl -we'INIT { eval "CHECK {print qq:in check in init\n:}" } print "hi";'

Since the CHECK blocks don't actually get run, the warning should still
get generated. Does PL_main_start (and PL_main_root, etc..) need to get
set even when it's just an OP_STUB?  Or is this an unlikely / illogical

-- Matthew Horsfall (alh)

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About