Skip to content

fix: call subs installed through a typeglob in bareword print arguments #1163

Description

@fglock

Summary

A subroutine installed through a typeglob assignment at runtime is not invoked
when it is the first argument of an unparenthesized print call.

Reproducer

no strict 'refs';
*bar = sub { 'glob-installed' };
print bar(), "\n";

Expected behavior

Perl 5.42 prints:

glob-installed

Actual behavior

Both PerlOnJava backends exit successfully but print only the newline.

Investigation notes

The typeglob assignment does install a callable subroutine. The following
forms work in both backends:

my $value = bar();
print $value, "\n";

my $name = 'bar';
print &$name(), "\n";

print 'prefix=', bar(), "\n";

The failure is therefore not general dynamic-sub lookup. It is a narrow
parse/emission problem for the bareword call as the leading argument of the
unparenthesized print form. PerlOnJava also rejects the otherwise valid
parenthesized spelling print(bar(), "\n") with a syntax error, which may be
related.

Impact

This breaks runtime method/function registration patterns used by plugin
systems, DSLs, generated code, and legacy Perl that installs subs by glob
assignment. The silent empty result is more hazardous than a compile-time
failure.

Acceptance criteria

  • The reproducer prints glob-installed on both backends.
  • The parenthesized print(bar(), "\\n") spelling is accepted and has the
    same result as Perl.
  • Preserve dynamic lookup: a sub installed after compilation must remain
    callable at the call site.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions