Preserve imported CV captured by code reference across namespace cleanup

未关闭
#2,130 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java, perl
领域
backend, testing

调研方向

Start by reading EmitSubroutine and GlobalVariable.getGlobalCodeRefForNamedReference, then trace how the interpreter handles the same captured &name reference after namespace::clean removes the package symbol. Add a focused regression test for capture, cleanup, and invocation; check it under standard Perl and on both PerlOnJava backends, while confirming the direct-call behavior covered by PR #694 remains intact.

由索引模型根据 Issue 内容生成。

描述

area:parser area:runtime bug

Summary

Subclass-Of 0.009 fails when its Moo attribute helper captures the imported has function with &has, runs namespace::clean, and invokes the captured code reference. Perl 5 preserves the imported CV even after the package stash entry is cleaned. PerlOnJava instead calls an undefined stub.

This is reproducible on both PerlOnJava execution backends and affects the upstream t/03moo.t test.

Reproducer

my $has = eval q{
    package DirectMooEval;
    use Moo;
    my $has = \&has;
    use namespace::clean;
    return $has;
};
die $@ unless $has;
$has->("foo", is => "ro");

Expected: the captured CV remains callable and the attribute is installed.

Actual on PerlOnJava: Undefined subroutine &DirectMooEval::has called.

System Perl 5.34.1 passes this focused reproducer. The archived CPAN oracle ran Perl 5.42.2 and passed the full Subclass-Of suite.

CPAN evidence

  • Distribution: Subclass-Of 0.009
  • Run: 20261119-133823-51077
  • Standard Perl: all available upstream tests pass (80 tests; Mouse-dependent test skipped)
  • PerlOnJava: 61/63 tests; failures in t/03moo.t, t/07warnings.t, and t/08lazy.t
  • The focused t/03moo.t failure was reproduced on both JVM and interpreter with PerlOnJava commit aa51fb913, OpenJDK 24.0.2, macOS arm64.

The actionable scope here is the imported CV capture failure in t/03moo.t. The other failing files are recorded as run evidence and have not been established as the same defect.

Root-cause evidence

The upstream sequence captures the imported function before use namespace::clean removes its package entry. A code reference created before that cleanup must continue to point to the imported CV.

PerlOnJava’s JVM emitter currently resolves a named code reference through GlobalVariable.getGlobalCodeRefForNamedReference when the expression runs (EmitSubroutine). The interpreter path also fails to retain a callable CV through the same cleanup sequence. This indicates a mismatch in when &name binds an imported CV and how that binding survives package-stash cleanup; it is not simply a missing Moo dependency or an import that never ran.

PR #694 covers imported CVs for direct calls across stash cleanup, but not a captured &name reference invoked after cleanup. Closed issue #1548 covers caller metadata and is unrelated to this binding behavior.

Acceptance

  • Add a focused project regression test for capturing an imported CV, cleaning its package symbol, and then calling the saved reference.
  • Validate the behavior under standard Perl.
  • Make the regression pass on both JVM and interpreter backends.
  • Preserve the direct-call behavior covered by PR #694.
主要语言
Perl
星标
67
派生
8
平均合并
5 小时 12 分钟
30 天内合并 PR
131

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

fglock/PerlOnJava 的其他 Issue

查看 fglock/PerlOnJava 的全部 Issue

相似的 Issue

更多 Perl Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。