Re: Proposed feature: die on compile with undefined functions
[email protected] (Chris Prather)
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <CAEFJ16_oF9XG-Oz5jnUkfhXUE4GdD0KUV1GaWhg5E8Zbc0Sh+A@mail.gmail.com> |
On Thu, Jan 29, 2026 at 12:18 PM demerphq <[email protected]> wrote: > > On Thu, 29 Jan 2026, 11:52 Philippe Bruhat (BooK), <[email protected]> wrote: >> >> On Wed, Jan 28, 2026 at 11:59:47AM -0600, David Condon wrote: >> > >> > *1. Here is a problem* >> > Scripts that have undeclared subroutines will run, even though the >> > subroutines are not declared/loaded/whatever: >> > >> > There are no syntax changes. The only change is that undefined subroutines >> > would be treated the same way that undefined scalars are treated. >> >> s/undefined scalares/undeclared scalars/ >> >> > I want perl to check for the undefined function max before running the >> > script, similarly to the way that this 1-line script: >> >> > *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 > > > Indeed, "halting problem" hard. > >> 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 > > > And while a super strict mode could require forward declarations for this exact case there are others where we document that forward references to fully qualified subs should work. I may be naive here but the argument that symbols can be created at runtime applies to variables too doesn't it? » perl -E'eval q[our $x = 1]; say $x' 1 » perl -M5.40.0 -E'eval q[our $x = 1]; say $x' Global symbol "$x" requires explicit package name (did you forget to declare "my $x"?) at -e line 1. Execution of -e aborted due to compilation errors. » perl -M5.40.0 -E'BEGIN { eval q[our $x = 1]; } say $x' Variable "$x" is not imported at -e line 1. Global symbol "$x" requires explicit package name (did you forget to declare "my $x"?) at -e line 1. Execution of -e aborted due to compilation errors. » perl -M5.40.0 -E'BEGIN { eval q[our $x = 1]; } say $main::x' 1 » perl -M5.40.0 -E'eval q[our $x = 1]; say $main::x' Name "main::x" used only once: possible typo at -e line 1. 1 -Chris