Honor scalar context for sort returned from a subroutine

オープン
#1,991 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@fglock がすでに取り組んでいます。

2026年11月6日 から。

  • #1992 @fglock による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
perl
領域
backend

調査の方向性

Start by reviewing PR #1992, which is already open and describes the fix across the JVM and interpreter backends. Trace how a subroutine return passes runtime context to sort, then run the focused regression and scalar-sort tests on both backends. Done means scalar callers receive Perl's undef result while list behavior remains covered.

索引モデルが issue の本文から書いたものです。

説明

area:runtime bug

Summary

sort in a subroutine return did not honor the caller's scalar context. Perl returns undef for sort in scalar context, but PerlOnJava returned the number of sorted values. This broke DataCube 0.01's tables method, which returns sort keys ... and is called in scalar context by its test suite.

Minimal reproducer

sub f { return sort qw(a b c) }
my $x = f();
print defined($x) ? "<$x>\n" : "undef\n";

Expected under system Perl: undef

Before the fix, PerlOnJava returned <3> on both JVM and interpreter backends.

Evidence

  • CPAN distribution: DataCube 0.01; random tester run 20261106-154847-45334.
  • System Perl 5.42.2: upstream make test passed, 26 tests.
  • PerlOnJava 5.44.1, build commit 13db7bd4a0: t/00_use.t exited 255 on both JVM and interpreter after 15 assertions, with Can't use string ("40") as a HASH ref.
  • The DataCube test assigns $cube->tables to a scalar. DataCube::tables returns sort keys ...; the scalar result was then treated as a hash reference.

Confirmed cause and fix

Static scalar-context sort was already handled. In a subroutine return, however, the caller's context is dynamic: PerlOnJava retained the sorted list and generic return handling scalarized it to the list length. PR #1992 passes the runtime context to sort on both backends, preserving input evaluation while skipping the comparator and returning undef for a scalar caller.

The focused regression and existing scalar-sort tests pass on system Perl, JVM, and interpreter. The full repository make and documentation link check pass. The DataCube suite progresses beyond the former failure, but later tests exceed the bounded 180-second runs; a full post-fix DataCube suite pass is not claimed.

主要言語
Perl
スター
65
フォーク
8
平均マージ
5時間 57分
マージ済み PR(30日)
177

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fglock/PerlOnJava のほかの issue

fglock/PerlOnJava の issue をすべて見る

似ている issue

Perl の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。