Honor scalar context for sort returned from a subroutine

Offen
#1,991 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@fglock arbeitet bereits daran.

Seit 06.11.2026.

  • #1992 von @fglock — offen

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
25/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Veraltet
Tech-Stack
perl
Bereich
backend

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Perl
Sterne
65
Forks
8
Ø Merge
5 Std. 57 Min.
Gemergte PRs (30 T.)
177

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus fglock/PerlOnJava

Alle Issues in fglock/PerlOnJava

Ähnliche Issues

Weitere Issues zu Perl

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.