Re: Proposed feature: die on compile with undefined functions
[email protected] (Michael Conrad)
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <[email protected]> |
On 1/29/26 5:52 AM, Philippe Bruhat (BooK) wrote:
>> *4. Here are potential problems*
>>
>> I am unaware of any. I just want something that will happen anyway to
>> happen sooner to save time. This change *shouldn't *be buggy.
> The problem is see is that it's extremely hard to detect if a function
> will be defined by the time Perl tries to call it:
>
> use v5.42;
> require List::Util;
> List::Util->import("max");
> say max( 1..10, -1..7);
>
> All of those lines happens at run time, and max is available by the time
> it's called. At the end of compilation, though, max is not defined.
>
While lots of dynamic ways exist to define a sub before it gets used, I
would argue that in a vast majority of cases by ordinary users, the sub
will either be declared in the body of code itself, or imported into
their package in the BEGIN phase, or imported it into their scope
lexically by some means. It seems reasonable to me that there could be
a perl feature to be strict about wanting the sub to be declared.
Something like `use experimental 'strict_declared_subs';`
It seems like it might be easy to add a flag so that when parser sees
`foo(1,2,3)` and checks lexically and in the package stash and doesn't
find the sub, instead of auto-vivifying it, it could just croak. What
non-esoteric cases would that break?
-Mike C